From 0e96734e9d24a2fb4780df8ec91180f4ea22890a Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Wed, 20 Dec 2023 14:26:56 +0800 Subject: [PATCH] fix golangci-lint Signed-off-by: dongjiang1989 --- .github/workflows/go.yml | 33 +++++++++++++++++++-------------- .golangci.yml | 7 +++++++ pkg/csi/controllerserver.go | 4 ++-- 3 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 479e2bdc..80d9d217 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,27 +13,32 @@ on: jobs: build: - name: ubuntu - Go v1.18 + name: ubuntu - Go v1.19 runs-on: ubuntu-latest steps: - - - name: Set up Go + - name: Setup Go uses: actions/setup-go@v2 with: go-version: '1.19' - id: go - - name: Check out code into the Go module directory + - name: Checkout uses: actions/checkout@v2 with: - ref: ${{ github.ref }} - path: src/github.com/alibaba/open-local - - - name: Install go ci lint - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.3 - - - name: Run Linter - run: golangci-lint run -v --timeout=10m - working-directory: src/github.com/alibaba/open-local + submodules: true + - name: Cache Go Dependencies + uses: actions/cache@v2 + with: + path: .work/pkg + key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-pkg- + + # This action uses its own setup-go, which always seems to use the latest + # stable version of Go. We could run 'make lint' to ensure our desired Go + # version, but we prefer this action because it leaves 'annotations' (i.e. + # it comments on PRs to point out linter violations). + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + version: 'v1.49' diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..63e2ac7b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,7 @@ +linters: + disable-all: true + enable: + - gosimple + - structcheck + - typecheck + - varcheck diff --git a/pkg/csi/controllerserver.go b/pkg/csi/controllerserver.go index ee667860..ce0cf486 100644 --- a/pkg/csi/controllerserver.go +++ b/pkg/csi/controllerserver.go @@ -817,8 +817,8 @@ func getNodeAddr(node *v1.Node, nodeID string, useNodeHostname bool) (string, er func GetNodeIP(node *v1.Node, nodeID string) (net.IP, error) { addresses := node.Status.Addresses addressMap := make(map[v1.NodeAddressType][]v1.NodeAddress) - for i := range addresses { - addressMap[addresses[i].Type] = append(addressMap[addresses[i].Type], addresses[i]) + for _, v := range addresses { + addressMap[v.Type] = append(addressMap[v.Type], v) } if addresses, ok := addressMap[v1.NodeInternalIP]; ok { return net.ParseIP(addresses[0].Address), nil