diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml new file mode 100644 index 00000000..e9c8fc1e --- /dev/null +++ b/.github/linters/.golangci.yml @@ -0,0 +1,42 @@ +--- +######################### +######################### +## Golang Linter rules ## +######################### +######################### + +# configure golangci-lint +# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +run: + skip-files: + - zz_generated* + - suite_test.go + timeout: 3m + +issues: + exclude-rules: + - path: _test\.go + linters: + - dupl + - gosec + - goconst + +linters: + disable: + - typecheck + enable: + - nilerr + - whitespace + - gofmt + - misspell + +linters-settings: + errcheck: + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: true + govet: + # report about shadowed variables + check-shadowing: false + gosimple: + checks: [ "-S1019" ] diff --git a/.github/linters/.yaml-lint.yml b/.github/linters/.yaml-lint.yml new file mode 100644 index 00000000..e1caa425 --- /dev/null +++ b/.github/linters/.yaml-lint.yml @@ -0,0 +1,14 @@ +extends: default + +rules: + line-length: disable + truthy: disable + brackets: disable + trailing-spaces: disable + document-start: disable + indentation: disable + comments: disable + comments-indentation: disable + colons: disable + empty-lines: disable + new-line-at-end-of-file: disable diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 00000000..82483ecd --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,82 @@ +--- +################################# +################################# +## Super Linter GitHub Actions ## +################################# +################################# +name: Lint Full Codebase + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +############################# +# Start the job on all push # +############################# +on: [ push, pull_request ] + +############### +# Set the Job # +############### +jobs: + golangci: + name: Go Linter + runs-on: ubuntu-18.04 + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - name: Deps + run: | + sudo apt update + sudo apt install -y build-essential + sudo apt install -y libdevmapper-dev + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - uses: actions/checkout@v2 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.42.1 + args: -c=".github/linters/.golangci.yml" + build: + # Name the Job + name: Super Linter (non-Go) + # Set the agent to run on + runs-on: ubuntu-latest + + ################## + # Load all steps # + ################## + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + ########################## + # Checkout the code base # + ########################## + - name: Checkout Code + uses: actions/checkout@v2 + with: + # Full git history is needed to get a proper list of changed files within `super-linter` + fetch-depth: 0 + + ################################ + # Run Linter against code base # + ################################ + - name: super-linter + uses: github/super-linter@v4 + env: + VALIDATE_ALL_CODEBASE: true + VALIDATE_SHELL_SHFMT: true + VALIDATE_YAML: true + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index aacb45f7..368d8c38 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/controllers/node_label_sync_test.go b/controllers/node_label_sync_test.go index ee50481d..c2478e60 100644 --- a/controllers/node_label_sync_test.go +++ b/controllers/node_label_sync_test.go @@ -82,9 +82,12 @@ func SetupNodeLabelSyncTest(ctx context.Context, isStorageOS bool, createLabels // getCSIAnnotation is a helper to return a valid StorageOS CSI Driver annotation. func getCSIAnnotation() (string, string) { - driverMap, _ := json.Marshal(map[string]string{ + driverMap, err := json.Marshal(map[string]string{ provisioner.DriverName: uuid.New().String(), }) + if err != nil { + println(err) + } return provisioner.NodeDriverAnnotationKey, string(driverMap) } diff --git a/internal/controllers/sharedvolume/controller.go b/internal/controllers/sharedvolume/controller.go index bf29a350..092e29ea 100644 --- a/internal/controllers/sharedvolume/controller.go +++ b/internal/controllers/sharedvolume/controller.go @@ -152,6 +152,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err != nil { // Non StorageOS shared volume, nothing to do. r.log.Info("non StorageOS shared volume", "name", vol.Name) + //lint:ignore nilerr if non StorageOS nothing to do return ctrl.Result{}, nil }