diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index c63ff78954a..04be6e09db0 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -46,6 +46,12 @@ issues: text: should not be used because managedFields was removed path: _test.go$ + # Adding unversioned feature gates is allowed in tests + - linters: + - forbidigo + text: should not use MutableFeatureGate.Add, use AddVersioned instead + path: _test.go$ + # The Kubernetes naming convention for conversion functions uses underscores # and intentionally deviates from normal Go conventions to make those function # names more readable. Same for SetDefaults_*. @@ -185,6 +191,10 @@ linters-settings: # please keep this alphabetized - p: \.Extract pkg: ^k8s\.io/client-go/applyconfigurations/ 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$ 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-strict.yaml b/hack/golangci-strict.yaml index 4db67b871e7..c96b3cbabe8 100644 --- a/hack/golangci-strict.yaml +++ b/hack/golangci-strict.yaml @@ -46,6 +46,12 @@ issues: text: should not be used because managedFields was removed path: _test.go$ + # Adding unversioned feature gates is allowed in tests + - linters: + - forbidigo + text: should not use MutableFeatureGate.Add, use AddVersioned instead + path: _test.go$ + # The Kubernetes naming convention for conversion functions uses underscores # and intentionally deviates from normal Go conventions to make those function # names more readable. Same for SetDefaults_*. @@ -231,6 +237,10 @@ linters-settings: # please keep this alphabetized - p: \.Extract pkg: ^k8s\.io/client-go/applyconfigurations/ 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 revive: # Only these rules are enabled. rules: diff --git a/hack/golangci.yaml b/hack/golangci.yaml index 2909f0d3ef1..b19670f6d1c 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -46,6 +46,12 @@ issues: text: should not be used because managedFields was removed path: _test.go$ + # Adding unversioned feature gates is allowed in tests + - linters: + - forbidigo + text: should not use MutableFeatureGate.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 # with different owners it's hard to fix everything in a single pr. This will therefore be done in multiple prs. - path: (pkg/volume/*|test/*|azure/*|pkg/cmd/wait*|request/bearertoken/*|metrics/*|filters/*) @@ -233,6 +239,10 @@ linters-settings: # please keep this alphabetized - p: \.Extract pkg: ^k8s\.io/client-go/applyconfigurations/ 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: - equalFold diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 7dcae86f2d6..35db63b01e1 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -46,6 +46,12 @@ issues: text: should not be used because managedFields was removed path: _test.go$ + # Adding unversioned feature gates is allowed in tests + - linters: + - forbidigo + text: should not use MutableFeatureGate.Add, use AddVersioned instead + path: _test.go$ + {{- if .Base}} # TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components @@ -189,6 +195,10 @@ linters-settings: # please keep this alphabetized - p: \.Extract pkg: ^k8s\.io/client-go/applyconfigurations/ 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$ pkg: ^github.com/onsi/gomega$ diff --git a/pkg/features/client_adapter.go b/pkg/features/client_adapter.go index a24a1f8730c..00a0fd92ab4 100644 --- a/pkg/features/client_adapter.go +++ b/pkg/features/client_adapter.go @@ -65,7 +65,7 @@ func (a *clientAdapter) Add(in map[clientfeatures.Feature]clientfeatures.Feature } out[featuregate.Feature(name)] = converted } - return a.mfg.Add(out) + return a.mfg.Add(out) //nolint:forbidigo // No need to support versioned feature gates in client adapter } // Set implements the unexported interface that client-go feature gate testing expects for diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index e0d37c5bfb7..8b42961e264 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -865,7 +865,7 @@ const ( ) func init() { - runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)) + runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)) //nolint:forbidigo // TODO(https://github.com/kubernetes/enhancements/tree/master/keps/sig-architecture/4330-compatibility-versions): Remove this once we complete the migration to versioned feature gates runtime.Must(utilfeature.DefaultMutableFeatureGate.AddVersioned(defaultVersionedKubernetesFeatureGates)) runtime.Must(zpagesfeatures.AddFeatureGates(utilfeature.DefaultMutableFeatureGate)) diff --git a/staging/src/k8s.io/apiserver/pkg/features/kube_features.go b/staging/src/k8s.io/apiserver/pkg/features/kube_features.go index e8f18d78591..162542b0e05 100644 --- a/staging/src/k8s.io/apiserver/pkg/features/kube_features.go +++ b/staging/src/k8s.io/apiserver/pkg/features/kube_features.go @@ -250,7 +250,7 @@ const ( ) func init() { - runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)) + runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)) //nolint:forbidigo // TODO(https://github.com/kubernetes/enhancements/tree/master/keps/sig-architecture/4330-compatibility-versions): Remove this once we complete the migration to versioned feature gates runtime.Must(utilfeature.DefaultMutableFeatureGate.AddVersioned(defaultVersionedKubernetesFeatureGates)) } diff --git a/staging/src/k8s.io/component-base/logs/api/v1/kube_features.go b/staging/src/k8s.io/component-base/logs/api/v1/kube_features.go index 4cfc69f8919..7dd4a495433 100644 --- a/staging/src/k8s.io/component-base/logs/api/v1/kube_features.go +++ b/staging/src/k8s.io/component-base/logs/api/v1/kube_features.go @@ -68,5 +68,5 @@ func featureGates() map[featuregate.Feature]featuregate.FeatureSpec { // AddFeatureGates adds all feature gates used by this package. func AddFeatureGates(mutableFeatureGate featuregate.MutableFeatureGate) error { - return mutableFeatureGate.Add(featureGates()) + return mutableFeatureGate.Add(featureGates()) //nolint:forbidigo // The logging feature gates are by design unversioned (perpetual alpha/beta). } diff --git a/test/e2e/framework/internal/unittests/bugs/features/features.go b/test/e2e/framework/internal/unittests/bugs/features/features.go index 092ea8a8bf0..3cd32d262cd 100644 --- a/test/e2e/framework/internal/unittests/bugs/features/features.go +++ b/test/e2e/framework/internal/unittests/bugs/features/features.go @@ -29,7 +29,7 @@ const ( ) func init() { - runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(testFeatureGates)) + runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(testFeatureGates)) //nolint:forbidigo // Part of a unit test. } var testFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ diff --git a/test/e2e/framework/internal/unittests/features/kube_features.go b/test/e2e/framework/internal/unittests/features/kube_features.go index 257701c2bb7..2a3ec92504c 100644 --- a/test/e2e/framework/internal/unittests/features/kube_features.go +++ b/test/e2e/framework/internal/unittests/features/kube_features.go @@ -27,7 +27,7 @@ const ( ) func init() { - runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)) + runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)) //nolint:forbidigo // Part of a unit test. } var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{