diff --git a/vertical-pod-autoscaler/hack/tools/kube-api-linter/.custom-gcl.yml b/vertical-pod-autoscaler/hack/tools/kube-api-linter/.custom-gcl.yml new file mode 100644 index 000000000000..f87534a41118 --- /dev/null +++ b/vertical-pod-autoscaler/hack/tools/kube-api-linter/.custom-gcl.yml @@ -0,0 +1,6 @@ +version: v2.3.1 +name: golangci-kube-api-linter +destination: ./bin +plugins: + - module: 'sigs.k8s.io/kube-api-linter' + version: v0.0.0-20250908163129-65a570bd22aa diff --git a/vertical-pod-autoscaler/hack/tools/kube-api-linter/.golangci-kal.yml b/vertical-pod-autoscaler/hack/tools/kube-api-linter/.golangci-kal.yml new file mode 100644 index 000000000000..4b59c3e3bab8 --- /dev/null +++ b/vertical-pod-autoscaler/hack/tools/kube-api-linter/.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/vertical-pod-autoscaler/hack/verify-kubelint.sh b/vertical-pod-autoscaler/hack/verify-kubelint.sh new file mode 100755 index 000000000000..10d9ccce3a18 --- /dev/null +++ b/vertical-pod-autoscaler/hack/verify-kubelint.sh @@ -0,0 +1,40 @@ +#!/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" + +echo "installing dependencies" +go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest + +cd $(dirname "${BASH_SOURCE}")/.. +SCRIPT_ROOT="$PWD" + +TOOLS_DIR="${PWD}/hack/tools/kube-api-linter" +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 "${SCRIPT_ROOT}" + +"${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}"