From 50dc876bc31fc710180494c8cf191d97e6748e90 Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Mon, 3 Nov 2025 21:43:18 -0800 Subject: [PATCH 1/7] #8325 Adds kubeapi linter to the project --- hack/install-verify-tools.sh | 2 ++ hack/tools/.custom-gcl.yml | 6 ++++ hack/tools/.golangci-kal.yml | 53 ++++++++++++++++++++++++++++++++++++ hack/verify-kubelint.sh | 47 ++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 hack/tools/.custom-gcl.yml create mode 100644 hack/tools/.golangci-kal.yml create mode 100755 hack/verify-kubelint.sh diff --git a/hack/install-verify-tools.sh b/hack/install-verify-tools.sh index aad2127dff7c..49519a6b910d 100755 --- a/hack/install-verify-tools.sh +++ b/hack/install-verify-tools.sh @@ -26,4 +26,6 @@ go install github.com/tools/godep@latest go install github.com/client9/misspell/cmd/misspell@latest +go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest + # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/tools/.custom-gcl.yml b/hack/tools/.custom-gcl.yml new file mode 100644 index 000000000000..fd0d8686a3b6 --- /dev/null +++ b/hack/tools/.custom-gcl.yml @@ -0,0 +1,6 @@ +version: v2.5.0 +name: golangci-kube-api-linter +destination: ./bin +plugins: + - module: 'sigs.k8s.io/kube-api-linter' + version: v0.0.0-20250908163129-65a570bd22aa diff --git a/hack/tools/.golangci-kal.yml b/hack/tools/.golangci-kal.yml new file mode 100644 index 000000000000..4b59c3e3bab8 --- /dev/null +++ b/hack/tools/.golangci-kal.yml @@ -0,0 +1,53 @@ +version: "2" +run: + go: "1.24" + allow-parallel-runners: true +linters: + default: none + enable: + - kubeapilinter # linter for Kube API conventions + settings: + custom: + kubeapilinter: + type: module + description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices. + settings: + linters: + enable: + #- "commentstart" # Ensure comments start with the serialized version of the field name. + #- "conditions" # Ensure conditions have the correct json tags and markers. + #- "conflictingmarkers" + #- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields. + #- "integers" # Ensure only int32 and int64 are used for integers. + #- "jsontags" # Ensure every field has a json tag. + #- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. + #- "nobools" # Bools do not evolve over time, should use enums instead. + #- "nodurations" # Prevents usage of `Duration` types. + #- "nofloats" # Ensure floats are not used. + #- "nomaps" # Ensure maps are not used. + #- "nonullable" # Ensure that types and fields do not have the nullable marker. + #- "optionalorrequired" # Every field should be marked as `+optional` or `+required`. + #- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. + #- "ssatags" # Ensure array fields have the appropriate listType markers + #- "statusoptional" # Ensure all first children within status should be optional. + #- "statussubresource" # All root objects that have a `status` field should have a status subresource. + #- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once. + disable: + - "*" # Disable all by default. + lintersConfig: + + + exclusions: + build-tags: + - ignore_autogenerated + paths: + - ".*_test.go" # Exclude test files. + rules: + ## KAL should only run on APIS folders. + - path-except: "apis//*" + linters: + - kubeapilinter + +issues: + max-same-issues: 0 + max-issues-per-linter: 0 diff --git a/hack/verify-kubelint.sh b/hack/verify-kubelint.sh new file mode 100755 index 000000000000..752a9dec2baf --- /dev/null +++ b/hack/verify-kubelint.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Copyright 2014 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +echo "verify-kubelint" + +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +cd "${KUBE_ROOT}" +ROOT_DIR="$PWD" + +TOOLS_DIR="${ROOT_DIR}/hack/tools" +TOOLS_BIN_DIR="${TOOLS_DIR}/bin" + +GOLANGCI_LINT_BIN=${GOLANGCI_LINT_BIN:-"golangci-lint"} +GOLANGCI_LINT_KAL_BIN=${GOLANGCI_LINT_KAL_BIN:-"${TOOLS_BIN_DIR}/golangci-kube-api-linter"} +GOLANGCI_LINT_CONFIG_PATH=${GOLANGCI_LINT_CONFIG_PATH:-"${TOOLS_DIR}/.golangci-kal.yml"} + +echo "creating custom golangci linter" +cd "${TOOLS_DIR}"; "${GOLANGCI_LINT_BIN}" custom + +cd "${ROOT_DIR}" + +PACKAGES=( + "${ROOT_DIR}/cluster-autoscaler" + "${ROOT_DIR}/vertical-pod-autoscaler" +) + +for package in "${PACKAGES[@]}"; do + cd "${package}" + "${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}" +done From 00376656758b7c37f7ba89a90ad28add93b0a422 Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Mon, 3 Nov 2025 22:52:52 -0800 Subject: [PATCH 2/7] bump go to 1.25 --- .github/workflows/verify.yaml | 2 +- hack/tools/.golangci-kal.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 2dbd70a26312..dd664445a0e4 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5.5.0 with: - go-version: '1.24.0' + go-version: '1.25.0' cache-dependency-path: | ${{ env.GOPATH}}/src/k8s.io/autoscaler/cluster-autoscaler/go.sum ${{ env.GOPATH}}/src/k8s.io/autoscaler/vertical-pod-autoscaler/go.sum diff --git a/hack/tools/.golangci-kal.yml b/hack/tools/.golangci-kal.yml index 4b59c3e3bab8..84f5947b2d61 100644 --- a/hack/tools/.golangci-kal.yml +++ b/hack/tools/.golangci-kal.yml @@ -1,6 +1,6 @@ version: "2" run: - go: "1.24" + go: "1.25" allow-parallel-runners: true linters: default: none From 3c0e537a7b1a05557eb0dadd40340a1bceff8bf2 Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Mon, 1 Dec 2025 13:49:08 -0800 Subject: [PATCH 3/7] PR comments --- .../tools/kube-api-linter}/.custom-gcl.yml | 0 .../tools/kube-api-linter}/.golangci-kal.yml | 0 .../hack}/verify-kubelint.sh | 20 +++++-------------- 3 files changed, 5 insertions(+), 15 deletions(-) rename {hack/tools => vertical-pod-autoscaler/hack/tools/kube-api-linter}/.custom-gcl.yml (100%) rename {hack/tools => vertical-pod-autoscaler/hack/tools/kube-api-linter}/.golangci-kal.yml (100%) rename {hack => vertical-pod-autoscaler/hack}/verify-kubelint.sh (74%) diff --git a/hack/tools/.custom-gcl.yml b/vertical-pod-autoscaler/hack/tools/kube-api-linter/.custom-gcl.yml similarity index 100% rename from hack/tools/.custom-gcl.yml rename to vertical-pod-autoscaler/hack/tools/kube-api-linter/.custom-gcl.yml diff --git a/hack/tools/.golangci-kal.yml b/vertical-pod-autoscaler/hack/tools/kube-api-linter/.golangci-kal.yml similarity index 100% rename from hack/tools/.golangci-kal.yml rename to vertical-pod-autoscaler/hack/tools/kube-api-linter/.golangci-kal.yml diff --git a/hack/verify-kubelint.sh b/vertical-pod-autoscaler/hack/verify-kubelint.sh similarity index 74% rename from hack/verify-kubelint.sh rename to vertical-pod-autoscaler/hack/verify-kubelint.sh index 752a9dec2baf..68976375bd8c 100755 --- a/hack/verify-kubelint.sh +++ b/vertical-pod-autoscaler/hack/verify-kubelint.sh @@ -20,11 +20,10 @@ set -o pipefail echo "verify-kubelint" -KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. -cd "${KUBE_ROOT}" -ROOT_DIR="$PWD" +HACK_DIR="$PWD" +VPA_ROOT="${HACK_DIR}/.." -TOOLS_DIR="${ROOT_DIR}/hack/tools" +TOOLS_DIR="${HACK_DIR}/tools/kube-api-linter" TOOLS_BIN_DIR="${TOOLS_DIR}/bin" GOLANGCI_LINT_BIN=${GOLANGCI_LINT_BIN:-"golangci-lint"} @@ -33,15 +32,6 @@ GOLANGCI_LINT_CONFIG_PATH=${GOLANGCI_LINT_CONFIG_PATH:-"${TOOLS_DIR}/.golangci-k echo "creating custom golangci linter" cd "${TOOLS_DIR}"; "${GOLANGCI_LINT_BIN}" custom +cd "${VPA_ROOT}" -cd "${ROOT_DIR}" - -PACKAGES=( - "${ROOT_DIR}/cluster-autoscaler" - "${ROOT_DIR}/vertical-pod-autoscaler" -) - -for package in "${PACKAGES[@]}"; do - cd "${package}" - "${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}" -done +"${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}" From a52f7f054c33723f9394f8ababa8a9cbd04ec369 Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Mon, 1 Dec 2025 16:04:05 -0800 Subject: [PATCH 4/7] build fix --- vertical-pod-autoscaler/hack/verify-kubelint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vertical-pod-autoscaler/hack/verify-kubelint.sh b/vertical-pod-autoscaler/hack/verify-kubelint.sh index 68976375bd8c..22b65cd6a99f 100755 --- a/vertical-pod-autoscaler/hack/verify-kubelint.sh +++ b/vertical-pod-autoscaler/hack/verify-kubelint.sh @@ -20,10 +20,10 @@ set -o pipefail echo "verify-kubelint" -HACK_DIR="$PWD" -VPA_ROOT="${HACK_DIR}/.." +cd $(dirname "${BASH_SOURCE}")/.. +SCRIPT_ROOT="$PWD" -TOOLS_DIR="${HACK_DIR}/tools/kube-api-linter" +TOOLS_DIR="${PWD}/hack/tools/kube-api-linter" TOOLS_BIN_DIR="${TOOLS_DIR}/bin" GOLANGCI_LINT_BIN=${GOLANGCI_LINT_BIN:-"golangci-lint"} @@ -32,6 +32,6 @@ GOLANGCI_LINT_CONFIG_PATH=${GOLANGCI_LINT_CONFIG_PATH:-"${TOOLS_DIR}/.golangci-k echo "creating custom golangci linter" cd "${TOOLS_DIR}"; "${GOLANGCI_LINT_BIN}" custom -cd "${VPA_ROOT}" +cd "${SCRIPT_ROOT}" "${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}" From 77b273a2645b5a20ef984e6c5b1953fb49c718ba Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Thu, 4 Dec 2025 14:46:43 -0800 Subject: [PATCH 5/7] PR comments 2 --- hack/install-verify-tools.sh | 2 -- vertical-pod-autoscaler/hack/verify-kubelint.sh | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hack/install-verify-tools.sh b/hack/install-verify-tools.sh index 49519a6b910d..aad2127dff7c 100755 --- a/hack/install-verify-tools.sh +++ b/hack/install-verify-tools.sh @@ -26,6 +26,4 @@ go install github.com/tools/godep@latest go install github.com/client9/misspell/cmd/misspell@latest -go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest - # ex: ts=2 sw=2 et filetype=sh diff --git a/vertical-pod-autoscaler/hack/verify-kubelint.sh b/vertical-pod-autoscaler/hack/verify-kubelint.sh index 22b65cd6a99f..10d9ccce3a18 100755 --- a/vertical-pod-autoscaler/hack/verify-kubelint.sh +++ b/vertical-pod-autoscaler/hack/verify-kubelint.sh @@ -20,6 +20,9 @@ set -o pipefail echo "verify-kubelint" +echo "installing dependencies" +go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest + cd $(dirname "${BASH_SOURCE}")/.. SCRIPT_ROOT="$PWD" From d5b5e1bf628f8fe1dd674cb46340de02e79a60a9 Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Fri, 5 Dec 2025 09:27:56 -0800 Subject: [PATCH 6/7] Downgrade go to 1.24 --- .github/workflows/verify.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index dd664445a0e4..2dbd70a26312 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5.5.0 with: - go-version: '1.25.0' + go-version: '1.24.0' cache-dependency-path: | ${{ env.GOPATH}}/src/k8s.io/autoscaler/cluster-autoscaler/go.sum ${{ env.GOPATH}}/src/k8s.io/autoscaler/vertical-pod-autoscaler/go.sum From 9729f404fce31e3945c3bca6d4298c9211ecec59 Mon Sep 17 00:00:00 2001 From: Kamil Kawka Date: Fri, 5 Dec 2025 09:34:26 -0800 Subject: [PATCH 7/7] Back to 1.25 --- .github/workflows/verify.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 2dbd70a26312..dd664445a0e4 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5.5.0 with: - go-version: '1.24.0' + go-version: '1.25.0' cache-dependency-path: | ${{ env.GOPATH}}/src/k8s.io/autoscaler/cluster-autoscaler/go.sum ${{ env.GOPATH}}/src/k8s.io/autoscaler/vertical-pod-autoscaler/go.sum