From 50c12c94f1b0be3a2958f1a7f1883ab17d6fbd64 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 26 Jul 2024 08:34:03 +0900 Subject: [PATCH 1/4] chore: fix golangci-lint (#307) --- .../{actionlintl.yml => actionlint.yml} | 0 .golangci.yaml | 15 +++++++++++++ .../client-go/indexer/main.go | 6 ++--- .../client-go/listerwatcher/README.md | 22 +++++++++---------- .../client-go/listerwatcher/main.go | 20 ++++++++--------- doc/doc.go | 3 +-- 6 files changed, 38 insertions(+), 28 deletions(-) rename .github/workflows/{actionlintl.yml => actionlint.yml} (100%) create mode 100644 .golangci.yaml diff --git a/.github/workflows/actionlintl.yml b/.github/workflows/actionlint.yml similarity index 100% rename from .github/workflows/actionlintl.yml rename to .github/workflows/actionlint.yml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..1c459ae7 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,15 @@ +run: + timeout: 5m # default is 1m +issues: + exclude-rules: + - path: contents/kubernetes-operator/controller-runtime/ + linters: + - errcheck + + - path: contents/kubernetes-extensions/kubernetes-scheduler/random-scheduler + linters: + - errcheck + + - path: contents/kubernetes-operator/client-go/ + linters: + - errcheck diff --git a/contents/kubernetes-operator/client-go/indexer/main.go b/contents/kubernetes-operator/client-go/indexer/main.go index 0f63eee0..9f1ccfd3 100644 --- a/contents/kubernetes-operator/client-go/indexer/main.go +++ b/contents/kubernetes-operator/client-go/indexer/main.go @@ -110,11 +110,11 @@ func exampleWithThreadSafeMap() { } func nameIndexer(obj interface{}) ([]string, error) { - switch obj.(type) { + switch v := obj.(type) { case string: - return []string{obj.(string)}, nil + return []string{v}, nil case User: - return []string{obj.(User).Name}, nil + return []string{v.Name}, nil default: return []string{}, errors.New("nameIndexer error") } diff --git a/contents/kubernetes-operator/client-go/listerwatcher/README.md b/contents/kubernetes-operator/client-go/listerwatcher/README.md index 7d7892c4..fa446c05 100644 --- a/contents/kubernetes-operator/client-go/listerwatcher/README.md +++ b/contents/kubernetes-operator/client-go/listerwatcher/README.md @@ -120,19 +120,17 @@ Code: You can get the event through `w.ResultChan()`. The example is simplified } loop: for { - select { - case event, ok := <-w.ResultChan(): - if !ok { - break loop - } - - meta, err := meta.Accessor(event.Object) - if err != nil { - continue - } - resourceVersion := meta.GetResourceVersion() - klog.Infof("event: %s, resourceVersion: %s", event.Type, resourceVersion) + event, ok := <-w.ResultChan() + if !ok { + break loop } + + meta, err := meta.Accessor(event.Object) + if err != nil { + continue + } + resourceVersion := meta.GetResourceVersion() + klog.Infof("event: %s, resourceVersion: %s", event.Type, resourceVersion) } ``` diff --git a/contents/kubernetes-operator/client-go/listerwatcher/main.go b/contents/kubernetes-operator/client-go/listerwatcher/main.go index 4443494c..833c91fb 100644 --- a/contents/kubernetes-operator/client-go/listerwatcher/main.go +++ b/contents/kubernetes-operator/client-go/listerwatcher/main.go @@ -70,18 +70,16 @@ func main() { } loop: for { - select { - case event, ok := <-w.ResultChan(): - if !ok { - break loop - } + event, ok := <-w.ResultChan() + if !ok { + break loop + } - meta, err := meta.Accessor(event.Object) - if err != nil { - continue - } - resourceVersion := meta.GetResourceVersion() - klog.Infof("event: %s, resourceVersion: %s", event.Type, resourceVersion) + meta, err := meta.Accessor(event.Object) + if err != nil { + continue } + resourceVersion := meta.GetResourceVersion() + klog.Infof("event: %s, resourceVersion: %s", event.Type, resourceVersion) } } diff --git a/doc/doc.go b/doc/doc.go index 94e97ac8..56e8a5e9 100644 --- a/doc/doc.go +++ b/doc/doc.go @@ -2,7 +2,6 @@ package doc import ( "fmt" - "io/ioutil" "os" "strings" ) @@ -103,7 +102,7 @@ func (m *MarkDownDoc) WriteTable(t *Table) *MarkDownDoc { } func (m *MarkDownDoc) Export(filename string) error { - return ioutil.WriteFile(filename, []byte(m.builder.String()), os.ModePerm) + return os.WriteFile(filename, []byte(m.builder.String()), os.ModePerm) } func (m *MarkDownDoc) GetLink(desc, url string) string { From ee23a59211606f97ee7998cfadc774af46734083 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 26 Jul 2024 08:43:37 +0900 Subject: [PATCH 2/4] chore: add status-check-go (#308) --- .github/workflows/actionlint.yml | 28 ++++++++++++++++++++++--- .github/workflows/go.yml | 36 ++++++++++++++++++++++++++++---- .github/workflows/pre-commit.yml | 2 +- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml index 5a4a5058..530458bf 100644 --- a/.github/workflows/actionlint.yml +++ b/.github/workflows/actionlint.yml @@ -2,12 +2,34 @@ name: actionlint on: pull_request: - branches: [main] - paths: - - ".github/workflows/*" jobs: + path-filter: + outputs: + workflows: ${{steps.changes.outputs.workflows}} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + + - uses: dorny/paths-filter@v3 + id: changes + with: + filters: | + workflows: + - '.github/workflows/*' + + status-check-actionlint: + runs-on: ubuntu-latest + needs: + - actionlint + permissions: {} + if: failure() + steps: + - run: exit 1 + actionlint: + needs: path-filter + if: ${{ needs.path-filter.outputs.workflows == 'true' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2f9132d7..cd58d215 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,16 +2,42 @@ name: go on: pull_request: - paths: - - 'contents/kubernetes-operator/**.go' - - .github/workflows/go.yml - - '**go**' push: branches: - main jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + go: ${{ steps.filter.outputs.go }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + go: + - 'contents/kubernetes-operator/**.go' + - .github/workflows/go.yml + - '**go**' + + status-check-go: + runs-on: ubuntu-latest + needs: + - test + - golangci-lint + permissions: {} + if: failure() + steps: + - run: exit 1 + test: + needs: changes + if: ${{ needs.changes.outputs.go == 'true' }} runs-on: ubuntu-latest steps: - name: checkout @@ -30,6 +56,8 @@ jobs: uses: codecov/codecov-action@v3 golangci-lint: + needs: changes + if: ${{ needs.changes.outputs.go == 'true' }} runs-on: ubuntu-latest steps: - name: checkout diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 756e3101..9bde00cd 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -10,4 +10,4 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 'pypy3.9' - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 From 27071de8198b10e50794318e7eb5dbef38e28860 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 26 Jul 2024 08:45:22 +0900 Subject: [PATCH 3/4] Update go.yml (#305) --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cd58d215..fe5369d1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -44,7 +44,7 @@ jobs: uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - name: setup go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version-file: go.mod From 2e0977f3ba00cfb09c5b42e043d627dfba5ecec9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 08:48:43 +0900 Subject: [PATCH 4/4] chore(deps): bump golang.org/x/net from 0.17.0 to 0.23.0 (#306) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Naka Masato --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 9a2a5a21..2d0f5095 100644 --- a/go.mod +++ b/go.mod @@ -49,11 +49,11 @@ require ( github.com/spf13/pflag v1.0.5 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/term v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index cbcb22d5..3d4ae7fa 100644 --- a/go.sum +++ b/go.sum @@ -135,8 +135,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -152,16 +152,16 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=