github.com/openshift/installer@v1.4.17/pkg/types/featuregates/featuregate.go (about) 1 package featuregates 2 3 // source: https://github.com/openshift/library-go/blob/c515269de16e5e239bd6e93e1f9821a976bb460b/pkg/operator/configobserver/featuregates/featuregate.go#L23-L28 4 5 import ( 6 "fmt" 7 8 "k8s.io/apimachinery/pkg/util/sets" 9 "k8s.io/apimachinery/pkg/util/validation/field" 10 11 configv1 "github.com/openshift/api/config/v1" 12 ) 13 14 // FeatureGate indicates whether a given feature is enabled or not 15 // This interface is heavily influenced by k8s.io/component-base, but not exactly compatible. 16 type FeatureGate interface { 17 // Enabled returns true if the key is enabled. 18 Enabled(key configv1.FeatureGateName) bool 19 } 20 21 type featureGate struct { 22 enabled sets.Set[configv1.FeatureGateName] 23 disabled sets.Set[configv1.FeatureGateName] 24 } 25 26 // GatedInstallConfigFeature contains fields that will be used to validate 27 // that required feature gates are enabled when gated install config fields 28 // are used. 29 // FeatureGateName: openshift/api feature gate required to enable the use of Field 30 // Condition: the check which determines whether the install config field is used, 31 // if Condition evaluates to True, FeatureGateName must be enabled to pass validation. 32 // Field: the gated install config field, Field is used in the error message. 33 type GatedInstallConfigFeature struct { 34 FeatureGateName configv1.FeatureGateName 35 Condition bool 36 Field *field.Path 37 } 38 39 func newFeatureGate(enabled, disabled []configv1.FeatureGateName) FeatureGate { 40 return &featureGate{ 41 enabled: sets.New[configv1.FeatureGateName](enabled...), 42 disabled: sets.New[configv1.FeatureGateName](disabled...), 43 } 44 } 45 46 // Enabled returns true if the provided feature gate is enabled 47 // in the active feature sets. 48 func (f *featureGate) Enabled(key configv1.FeatureGateName) bool { 49 if f.enabled.Has(key) { 50 return true 51 } 52 if f.disabled.Has(key) { 53 return false 54 } 55 56 panic(fmt.Errorf("feature %q is not registered in FeatureGates", key)) 57 }