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/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..84f5947b2d61 --- /dev/null +++ b/hack/tools/.golangci-kal.yml @@ -0,0 +1,53 @@ +version: "2" +run: + go: "1.25" + 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