diff --git a/.custom-gcl.yaml b/.custom-gcl.yaml new file mode 100644 index 00000000..32f38f2a --- /dev/null +++ b/.custom-gcl.yaml @@ -0,0 +1,6 @@ +version: v2.5.0 +name: golangci-lint-kube-api-linter +destination: ./bin +plugins: + - module: 'sigs.k8s.io/kube-api-linter' + version: 'v0.0.0-20251103104136-5fca1e8b5e9f' diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 5012e418..d22acc5d 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -36,6 +36,8 @@ jobs: uses: golangci/golangci-lint-action@v9 with: version: latest + - name: Run kube-api-linter + run: make run-kubeapilinter - name: Delete pre-installed shellcheck run: sudo rm -f $(which shellcheck) - name: Run shellcheck diff --git a/.golangci-kal.yaml b/.golangci-kal.yaml new file mode 100644 index 00000000..07d734bf --- /dev/null +++ b/.golangci-kal.yaml @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company +# SPDX-License-Identifier: Apache-2.0 +version: "2" +linters: + default: none + enable: + - kubeapilinter # linter for Kube API conventions + settings: + custom: + kubeapilinter: + type: module + description: KAL is the Kube-API-Linter and lints Kubernetes APIs based on API conventions and best practices. + settings: + linters: {} + lintersConfig: + conditions: + useProtobuf: Forbid + optionalfields: + pointers: + preference: WhenRequired + + exclusions: + generated: strict + paths: + - ".*_test.go" + - "zz_generated.*.go" + rules: + - path-except: "^api/" + linters: + - kubeapilinter +issues: + max-same-issues: 0 + max-issues-per-linter: 0 diff --git a/Makefile b/Makefile index 1ad56fe2..9f986c6b 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,15 @@ fmt: FORCE install-gofumpt @printf "\e[1;36m>> gofumpt -l -w .\e[0m\n" @gofumpt -l -w $(shell git ls-files '*.go' | grep -v '^internal/provider/openconfig') +bin/golangci-lint-kube-api-linter: + @printf "\e[1;36m>> Installing golangci-lint-kube-api-linter...\e[0m\n" + @golangci-lint custom + +run-kubeapilinter: FORCE bin/golangci-lint-kube-api-linter + @printf "\e[1;36m>> bin/golangci-lint-kube-api-linter run --config=.golangci-kal.yaml\e[0m\n" + @bin/golangci-lint-kube-api-linter config verify --config=.golangci-kal.yaml + @bin/golangci-lint-kube-api-linter run --config=.golangci-kal.yaml + # Run the e2e tests against a k8s cluster. test-e2e: FORCE @command -v kind >/dev/null 2>&1 || { \ diff --git a/Makefile.maker.yaml b/Makefile.maker.yaml index 45f3ab90..421f0abb 100644 --- a/Makefile.maker.yaml +++ b/Makefile.maker.yaml @@ -80,6 +80,15 @@ verbatim: | @printf "\e[1;36m>> gofumpt -l -w .\e[0m\n" @gofumpt -l -w $(shell git ls-files '*.go' | grep -v '^internal/provider/openconfig') + bin/golangci-lint-kube-api-linter: + @printf "\e[1;36m>> Installing golangci-lint-kube-api-linter...\e[0m\n" + @golangci-lint custom + + run-kubeapilinter: FORCE bin/golangci-lint-kube-api-linter + @printf "\e[1;36m>> bin/golangci-lint-kube-api-linter run --config=.golangci-kal.yaml\e[0m\n" + @bin/golangci-lint-kube-api-linter config verify --config=.golangci-kal.yaml + @bin/golangci-lint-kube-api-linter run --config=.golangci-kal.yaml + # Run the e2e tests against a k8s cluster. test-e2e: FORCE @command -v kind >/dev/null 2>&1 || { \