mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update kubernetes to latest
updating the kubernetes release to the latest in main go.mod Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
63c4c05b35
commit
5a66991bb3
62
vendor/k8s.io/client-go/features/envvar.go
generated
vendored
62
vendor/k8s.io/client-go/features/envvar.go
generated
vendored
@ -47,6 +47,10 @@ var _ Gates = &envVarFeatureGates{}
|
||||
//
|
||||
// Please note that environmental variables can only be set to the boolean value.
|
||||
// Incorrect values will be ignored and logged.
|
||||
//
|
||||
// Features can also be set directly via the Set method.
|
||||
// In that case, these features take precedence over
|
||||
// features set via environmental variables.
|
||||
func newEnvVarFeatureGates(features map[Feature]FeatureSpec) *envVarFeatureGates {
|
||||
known := map[Feature]FeatureSpec{}
|
||||
for name, spec := range features {
|
||||
@ -57,7 +61,8 @@ func newEnvVarFeatureGates(features map[Feature]FeatureSpec) *envVarFeatureGates
|
||||
callSiteName: naming.GetNameFromCallsite(internalPackages...),
|
||||
known: known,
|
||||
}
|
||||
fg.enabled.Store(map[Feature]bool{})
|
||||
fg.enabledViaEnvVar.Store(map[Feature]bool{})
|
||||
fg.enabledViaSetMethod = map[Feature]bool{}
|
||||
|
||||
return fg
|
||||
}
|
||||
@ -74,17 +79,34 @@ type envVarFeatureGates struct {
|
||||
// known holds known feature gates
|
||||
known map[Feature]FeatureSpec
|
||||
|
||||
// enabled holds a map[Feature]bool
|
||||
// enabledViaEnvVar holds a map[Feature]bool
|
||||
// with values explicitly set via env var
|
||||
enabled atomic.Value
|
||||
enabledViaEnvVar atomic.Value
|
||||
|
||||
// lockEnabledViaSetMethod protects enabledViaSetMethod
|
||||
lockEnabledViaSetMethod sync.RWMutex
|
||||
|
||||
// enabledViaSetMethod holds values explicitly set
|
||||
// via Set method, features stored in this map take
|
||||
// precedence over features stored in enabledViaEnvVar
|
||||
enabledViaSetMethod map[Feature]bool
|
||||
|
||||
// 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.
|
||||
// Enabled returns true if the key is enabled. If the key is not known, this call will panic.
|
||||
func (f *envVarFeatureGates) Enabled(key Feature) bool {
|
||||
if v, ok := f.wasFeatureEnabledViaSetMethod(key); ok {
|
||||
// ensue that the state of all known features
|
||||
// is loaded from environment variables
|
||||
// on the first call to Enabled method.
|
||||
if !f.hasAlreadyReadEnvVar() {
|
||||
_ = f.getEnabledMapFromEnvVar()
|
||||
}
|
||||
return v
|
||||
}
|
||||
if v, ok := f.getEnabledMapFromEnvVar()[key]; ok {
|
||||
return v
|
||||
}
|
||||
@ -94,6 +116,26 @@ func (f *envVarFeatureGates) Enabled(key Feature) bool {
|
||||
panic(fmt.Errorf("feature %q is not registered in FeatureGates %q", key, f.callSiteName))
|
||||
}
|
||||
|
||||
// Set sets the given feature to the given value.
|
||||
//
|
||||
// Features set via this method take precedence over
|
||||
// the features set via environment variables.
|
||||
func (f *envVarFeatureGates) Set(featureName Feature, featureValue bool) error {
|
||||
feature, ok := f.known[featureName]
|
||||
if !ok {
|
||||
return fmt.Errorf("feature %q is not registered in FeatureGates %q", featureName, f.callSiteName)
|
||||
}
|
||||
if feature.LockToDefault && feature.Default != featureValue {
|
||||
return fmt.Errorf("cannot set feature gate %q to %v, feature is locked to %v", featureName, featureValue, feature.Default)
|
||||
}
|
||||
|
||||
f.lockEnabledViaSetMethod.Lock()
|
||||
defer f.lockEnabledViaSetMethod.Unlock()
|
||||
f.enabledViaSetMethod[featureName] = featureValue
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getEnabledMapFromEnvVar will fill the enabled map on the first call.
|
||||
// This is the only time a known feature can be set to a value
|
||||
// read from the corresponding environmental variable.
|
||||
@ -119,7 +161,7 @@ func (f *envVarFeatureGates) getEnabledMapFromEnvVar() map[Feature]bool {
|
||||
featureGatesState[feature] = boolVal
|
||||
}
|
||||
}
|
||||
f.enabled.Store(featureGatesState)
|
||||
f.enabledViaEnvVar.Store(featureGatesState)
|
||||
f.readEnvVars.Store(true)
|
||||
|
||||
for feature, featureSpec := range f.known {
|
||||
@ -130,7 +172,15 @@ func (f *envVarFeatureGates) getEnabledMapFromEnvVar() map[Feature]bool {
|
||||
klog.V(1).InfoS("Feature gate default state", "feature", feature, "enabled", featureSpec.Default)
|
||||
}
|
||||
})
|
||||
return f.enabled.Load().(map[Feature]bool)
|
||||
return f.enabledViaEnvVar.Load().(map[Feature]bool)
|
||||
}
|
||||
|
||||
func (f *envVarFeatureGates) wasFeatureEnabledViaSetMethod(key Feature) (bool, bool) {
|
||||
f.lockEnabledViaSetMethod.RLock()
|
||||
defer f.lockEnabledViaSetMethod.RUnlock()
|
||||
|
||||
value, found := f.enabledViaSetMethod[key]
|
||||
return value, found
|
||||
}
|
||||
|
||||
func (f *envVarFeatureGates) hasAlreadyReadEnvVar() bool {
|
||||
|
Reference in New Issue
Block a user