Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this is ok?

  1. This github actions is for the entire repo. I am not sure which go version does cluster-autoscaler use
  2. Locally I get this:
ubuntu:~/autoscaler(pr-8737)$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.7.1
golangci/golangci-lint info checking GitHub for tag 'v2.7.1'
golangci/golangci-lint info found version: 2.7.1 for v2.7.1/linux/arm64
golangci/golangci-lint info installed /home/ubuntu/go/bin/golangci-lint
ubuntu:~/autoscaler(pr-8737)$ ./hack/install-verify-tools.sh 
go: finding module for package golang.org/x/tools/go/vcs
go: finding module for package github.com/kr/fs
go: finding module for package github.com/pmezard/go-difflib/difflib
go: finding module for package github.com/kr/pretty
go: found github.com/kr/fs in github.com/kr/fs v0.1.0
go: found github.com/kr/pretty in github.com/kr/pretty v0.3.1
go: found github.com/pmezard/go-difflib/difflib in github.com/pmezard/go-difflib v1.0.0
go: found golang.org/x/tools/go/vcs in golang.org/x/tools/go/vcs v0.1.0-deprecated
ubuntu:~/autoscaler(pr-8737)$  ./vertical-pod-autoscaler/hack/verify-kubelint.sh 
verify-kubelint
installing dependencies
creating custom golangci linter
INFO golangci-lint has version v2.5.0-custom-gcl-47DEQpj8HBSaTImW5JCeuQeRkm5NMpJWZG3hSuFU built with go1.24.7 from ? on 2025-12-05 09:59:57.074313026 +0000 UTC 
INFO [config_reader] Used config file hack/tools/kube-api-linter/.golangci-kal.yml 
Error: can't load config: the Go language version (go1.24) used to build golangci-lint is lower than the targeted Go version (1.25)
The command is terminated due to an error: can't load config: the Go language version (go1.24) used to build golangci-lint is lower than the targeted Go version (1.25)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it is possible to use go version lower than 1.25. golangci-lint started using 1.25 from version 2.4.0.
The kube-api-linter jumped straight from golangci-lint version 1.64 to 2.50.
There was a version in between that suppose to use golangci 2.0.2, but I do not know how find the artifact generated by that build.

cache-dependency-path: |
${{ env.GOPATH}}/src/k8s.io/autoscaler/cluster-autoscaler/go.sum
${{ env.GOPATH}}/src/k8s.io/autoscaler/vertical-pod-autoscaler/go.sum
Expand Down
2 changes: 2 additions & 0 deletions hack/install-verify-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions vertical-pod-autoscaler/hack/verify-kubelint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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"

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for me:

~/src/kubernetes/autoscaler/vertical-pod-autoscaler/hack (pr-8737)$ ./verify-kubelint.sh
verify-kubelint
creating custom golangci linter
Error: build process: clone golangci-lint: git clone --branch v2.5.0 --single-branch --depth 1 -c advice.detachedHead=false -q https://github.com/golangci/golangci-lint.git: exit status 128
The command is terminated due to an error: build process: clone golangci-lint: git clone --branch v2.5.0 --single-branch --depth 1 -c advice.detachedHead=false -q https://github.com/golangci/golangci-lint.git: exit status 128

I can't figure out why though, that clone works manually

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you run ./install-verify-tools.sh before ? It looks like it is an issue with the golangci-lint

I made a clean copy of the repo and I cannot reproduce it

➜  hack git:(pr-8737) ✗ pwd                 
/Users/kkawka/Repos/kkawka/autoscaler2/autoscaler/vertical-pod-autoscaler/hack
➜  hack git:(pr-8737) ./verify-kubelint.sh
verify-kubelint
creating custom golangci linter
INFO golangci-lint has version v2.5.0-custom-gcl-47DEQpj8HBSaTImW5JCeuQeRkm5NMpJWZG3hSuFU built with go1.25.1 from ? on 2025-12-02 21:48:40.927303 +0000 UTC 
INFO [config_reader] Used config file hack/tools/kube-api-linter/.golangci-kal.yml 
INFO maxprocs: Leaving GOMAXPROCS=10: CPU quota undefined 
INFO Loaded : kubeapilinter                       
INFO [goenv] Read go env for 24.4415ms: map[string]string{"GOCACHE":"/Users/kkawka/Library/Caches/go-build", "GOROOT":"/Users/kkawka/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.3.darwin-arm64"} 
INFO [lintersdb] Active 1 linters: [kubeapilinter] 
INFO [loader] Go packages loading at mode 8767 (deps|files|imports|name|types_sizes|compiled_files|exports_file) took 831.368583ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 8.50625ms 
INFO [linters_context/goanalysis] analyzers took 0s with no stages 
INFO [runner/exclusion_paths] Skipped 0 issues by pattern ".*_test.go" 
INFO [runner/exclusion_rules] Skipped 0 issues by rules: [Path Except: "apis//*", Linters: "kubeapilinter"] 
INFO [runner] processing took 24.874µs with stages: exclusion_paths: 19.458µs, exclusion_rules: 3.5µs, max_same_issues: 875ns, nolint_filter: 250ns, path_absoluter: 209ns, max_from_linter: 83ns, severity-rules: 42ns, path_shortener: 42ns, path_prettifier: 42ns, source_code: 42ns, cgo: 42ns, path_relativity: 42ns, diff: 42ns, fixer: 41ns, filename_unadjuster: 41ns, max_per_file_from_linter: 41ns, sort_results: 41ns, invalid_issue: 41ns, generated_file_filter: 0s, uniq_by_line: 0s 
INFO [runner] linters took 400.0775ms with stages: goanalysis_metalinter: 399.984709ms 
0 issues.
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 14 samples, avg is 56.5MB, max is 88.5MB 
INFO Execution took 1.26541s        

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks
Could this script be tweaked to not require calling another script first?

My preference is a standalone script that doesn't require a user to know that another script has to be run before.

Other than that, it worked as expected! Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, just keep in mind golangci-lint is a dependency for a kube-api-linter.
Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that makes sense. Thanks!

cd "${SCRIPT_ROOT}"

"${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}"