From 834a0d92cfab06f959368e8a629beb0fd207f861 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 7 Mar 2025 17:27:03 +0200 Subject: [PATCH 1/6] hack: fix settings for forbidigo linter --- hack/golangci-hints.yaml | 1 - hack/golangci.yaml | 1 - hack/golangci.yaml.in | 1 - 3 files changed, 3 deletions(-) diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index 90863541f27..b716ea07e60 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -205,7 +205,6 @@ linters-settings: # please keep this alphabetized msg: should not be used because managedFields was removed - p: \.Add$ pkg: ^k8s\.io/component-base/featuregate$ - type: ^MutableFeatureGate$ msg: should not use MutableFeatureGate.Add, use AddVersioned instead - p: ^gomega\.BeTrue$ pkg: ^github.com/onsi/gomega$ diff --git a/hack/golangci.yaml b/hack/golangci.yaml index f7c834116f3..34c4e3ab632 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -271,7 +271,6 @@ linters-settings: # please keep this alphabetized msg: should not be used because managedFields was removed - p: \.Add$ pkg: ^k8s\.io/component-base/featuregate$ - type: ^MutableFeatureGate$ msg: should not use MutableFeatureGate.Add, use AddVersioned instead gocritic: enabled-checks: diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 6c6ed5e99c6..06ad332b8d0 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -223,7 +223,6 @@ linters-settings: # please keep this alphabetized msg: should not be used because managedFields was removed - p: \.Add$ pkg: ^k8s\.io/component-base/featuregate$ - type: ^MutableFeatureGate$ msg: should not use MutableFeatureGate.Add, use AddVersioned instead {{- if .Hints}} - p: ^gomega\.BeTrue$ From a9d558de26335bc5b41e8722a33b6e398db2d7c9 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 10 Mar 2025 12:06:56 +0200 Subject: [PATCH 2/6] hack: verify golangci-lint config, update text --- hack/golangci-hints.yaml | 2 +- hack/golangci.yaml | 2 +- hack/golangci.yaml.in | 2 +- hack/verify-golangci-lint-config.sh | 7 ++++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index b716ea07e60..2ac2132b289 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -205,7 +205,7 @@ linters-settings: # please keep this alphabetized msg: should not be used because managedFields was removed - p: \.Add$ pkg: ^k8s\.io/component-base/featuregate$ - msg: should not use MutableFeatureGate.Add, use AddVersioned instead + msg: should not use Add, use AddVersioned instead - p: ^gomega\.BeTrue$ pkg: ^github.com/onsi/gomega$ msg: "it does not produce a good failure message - use BeTrueBecause with an explicit printf-style failure message instead, or plain Go: if ... { ginkgo.Fail(...) }" diff --git a/hack/golangci.yaml b/hack/golangci.yaml index 34c4e3ab632..7972d00d5c0 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -271,7 +271,7 @@ linters-settings: # please keep this alphabetized msg: should not be used because managedFields was removed - p: \.Add$ pkg: ^k8s\.io/component-base/featuregate$ - msg: should not use MutableFeatureGate.Add, use AddVersioned instead + msg: should not use Add, use AddVersioned instead gocritic: enabled-checks: - equalFold diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 06ad332b8d0..3ff7507143e 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -223,7 +223,7 @@ linters-settings: # please keep this alphabetized msg: should not be used because managedFields was removed - p: \.Add$ pkg: ^k8s\.io/component-base/featuregate$ - msg: should not use MutableFeatureGate.Add, use AddVersioned instead + msg: should not use Add, use AddVersioned instead {{- if .Hints}} - p: ^gomega\.BeTrue$ pkg: ^github.com/onsi/gomega$ diff --git a/hack/verify-golangci-lint-config.sh b/hack/verify-golangci-lint-config.sh index 236d3e589e5..83d11147599 100755 --- a/hack/verify-golangci-lint-config.sh +++ b/hack/verify-golangci-lint-config.sh @@ -15,7 +15,7 @@ # limitations under the License. # This script checks that all generated golangci-lint configurations -# are up-to-date. +# are up-to-date and the config hack/golangci.yaml is valid. set -o errexit set -o nounset @@ -24,4 +24,9 @@ set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${KUBE_ROOT}/hack/lib/verify-generated.sh" +golangci=("${GOBIN}/golangci-lint") +golangci_config="${KUBE_ROOT}/hack/golangci.yaml" + kube::verify::generated "" "Please run 'hack/update-golangci-lint-config.sh'" hack/update-golangci-lint-config.sh + +"${golangci[@]}" config verify --config="${golangci_config}" From 67f0e95b3ac537348deb370b98c4d75066403851 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 10 Mar 2025 14:31:08 +0200 Subject: [PATCH 3/6] hack: fix text --- hack/golangci-hints.yaml | 2 +- hack/golangci.yaml | 2 +- hack/golangci.yaml.in | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index 2ac2132b289..c2ce0914f78 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -48,7 +48,7 @@ issues: # Adding unversioned feature gates is allowed in tests - linters: - forbidigo - text: should not use MutableFeatureGate.Add, use AddVersioned instead + text: should not use Add, use AddVersioned instead path: _test.go$ # The Kubernetes naming convention for conversion functions uses underscores diff --git a/hack/golangci.yaml b/hack/golangci.yaml index 7972d00d5c0..5daa137e02a 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -48,7 +48,7 @@ issues: # Adding unversioned feature gates is allowed in tests - linters: - forbidigo - text: should not use MutableFeatureGate.Add, use AddVersioned instead + text: should not use Add, use AddVersioned instead path: _test.go$ # TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 3ff7507143e..a2987c4b33b 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -48,7 +48,7 @@ issues: # Adding unversioned feature gates is allowed in tests - linters: - forbidigo - text: should not use MutableFeatureGate.Add, use AddVersioned instead + text: should not use Add, use AddVersioned instead path: _test.go$ {{- if .Base}} From 77758c185b14fb100e7bffa1f27baa6a2bda05d8 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 10 Mar 2025 14:37:13 +0200 Subject: [PATCH 4/6] hack: verify to verify-golangci-lint.sh --- hack/verify-golangci-lint-config.sh | 7 +------ hack/verify-golangci-lint.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/hack/verify-golangci-lint-config.sh b/hack/verify-golangci-lint-config.sh index 83d11147599..236d3e589e5 100755 --- a/hack/verify-golangci-lint-config.sh +++ b/hack/verify-golangci-lint-config.sh @@ -15,7 +15,7 @@ # limitations under the License. # This script checks that all generated golangci-lint configurations -# are up-to-date and the config hack/golangci.yaml is valid. +# are up-to-date. set -o errexit set -o nounset @@ -24,9 +24,4 @@ set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${KUBE_ROOT}/hack/lib/verify-generated.sh" -golangci=("${GOBIN}/golangci-lint") -golangci_config="${KUBE_ROOT}/hack/golangci.yaml" - kube::verify::generated "" "Please run 'hack/update-golangci-lint-config.sh'" hack/update-golangci-lint-config.sh - -"${golangci[@]}" config verify --config="${golangci_config}" diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 72d8a9382ef..d0d47f0c6fa 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -129,6 +129,22 @@ if [ "${golangci_config}" ]; then GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin fi +# Verify that the given config is valid. "golangci-lint run" does not +# do that, which makes it easy to miss mistakes while editing the configuration. +if ! failures=$( ${GOBIN}/golangci-lint config verify --config="${golangci_config:-}" 2>&1 ); then + cat >&2 < Date: Mon, 10 Mar 2025 15:55:17 +0200 Subject: [PATCH 5/6] hack: fix shellcheck --- hack/verify-golangci-lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index d0d47f0c6fa..7e3950ef2d9 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -131,7 +131,7 @@ fi # Verify that the given config is valid. "golangci-lint run" does not # do that, which makes it easy to miss mistakes while editing the configuration. -if ! failures=$( ${GOBIN}/golangci-lint config verify --config="${golangci_config:-}" 2>&1 ); then +if ! failures=$( "${GOBIN}/golangci-lint" config verify --config="${golangci_config:-}" 2>&1 ); then cat >&2 < Date: Tue, 11 Mar 2025 11:45:45 -0700 Subject: [PATCH 6/6] Update hack/verify-golangci-lint.sh Co-authored-by: Benjamin Elder --- hack/verify-golangci-lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 7e3950ef2d9..8e48200567a 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -134,7 +134,7 @@ fi if ! failures=$( "${GOBIN}/golangci-lint" config verify --config="${golangci_config:-}" 2>&1 ); then cat >&2 <