client-go/features: warn when ordering initialization issue

ReplaceFeatureGates logs a warning when the default env var
implementation has been already used.
Such a situation indicates a potential ordering issue and usually is unwanted.

Kubernetes-commit: 04bbd3481f70825eea54b4b154a04d2496dcf652
This commit is contained in:
Lukasz Szaszkiewicz
2024-01-10 17:15:01 +01:00
committed by Kubernetes Publisher
parent ca4f3a73f7
commit e8a81a3a43
3 changed files with 35 additions and 0 deletions

View File

@@ -77,6 +77,10 @@ type envVarFeatureGates struct {
// enabled holds a map[Feature]bool
// with values explicitly set via env var
enabled atomic.Value
// readEnvVars holds the boolean value which
// indicates whether readEnvVarsOnce has been called.
readEnvVars atomic.Bool
}
// Enabled returns true if the key is enabled. If the key is not known, this call will panic.
@@ -116,6 +120,7 @@ func (f *envVarFeatureGates) getEnabledMapFromEnvVar() map[Feature]bool {
}
}
f.enabled.Store(featureGatesState)
f.readEnvVars.Store(true)
for feature, featureSpec := range f.known {
if featureState, ok := featureGatesState[feature]; ok {
@@ -127,3 +132,7 @@ func (f *envVarFeatureGates) getEnabledMapFromEnvVar() map[Feature]bool {
})
return f.enabled.Load().(map[Feature]bool)
}
func (f *envVarFeatureGates) hasAlreadyReadEnvVar() bool {
return f.readEnvVars.Load()
}