github.com/openshift/installer@v1.4.17/pkg/types/featuregates/featuregates.go (about) 1 package featuregates 2 3 // source: https://github.com/openshift/cluster-config-operator/blob/636a2dc303037e2561a243ae1ab5c5b953ddad04/pkg/cmd/render/render.go#L153 4 5 import ( 6 "strconv" 7 "strings" 8 9 "k8s.io/apimachinery/pkg/util/sets" 10 11 configv1 "github.com/openshift/api/config/v1" 12 features "github.com/openshift/api/features" 13 ) 14 15 func toFeatureGateNames(in []features.FeatureGateDescription) []configv1.FeatureGateName { 16 out := []configv1.FeatureGateName{} 17 for _, curr := range in { 18 out = append(out, curr.FeatureGateAttributes.Name) 19 } 20 21 return out 22 } 23 24 // completeFeatureGates identifies every known feature and ensures that is explicitly on or explicitly off. 25 func completeFeatureGates(knownFeatureSets map[configv1.FeatureSet]*features.FeatureGateEnabledDisabled, enabled, disabled []configv1.FeatureGateName) ([]configv1.FeatureGateName, []configv1.FeatureGateName) { 26 specificallyEnabledFeatureGates := sets.New[configv1.FeatureGateName]() 27 specificallyEnabledFeatureGates.Insert(enabled...) 28 29 knownFeatureGates := sets.New[configv1.FeatureGateName]() 30 knownFeatureGates.Insert(enabled...) 31 knownFeatureGates.Insert(disabled...) 32 for _, known := range knownFeatureSets { 33 for _, curr := range known.Disabled { 34 knownFeatureGates.Insert(curr.FeatureGateAttributes.Name) 35 } 36 for _, curr := range known.Enabled { 37 knownFeatureGates.Insert(curr.FeatureGateAttributes.Name) 38 } 39 } 40 41 return enabled, knownFeatureGates.Difference(specificallyEnabledFeatureGates).UnsortedList() 42 } 43 44 // FeatureGateFromFeatureSets creates a FeatureGate from the active feature sets. 45 func FeatureGateFromFeatureSets(knownFeatureSets map[configv1.FeatureSet]*features.FeatureGateEnabledDisabled, fs configv1.FeatureSet, customFS *configv1.CustomFeatureGates) FeatureGate { 46 if customFS != nil { 47 completeEnabled, completeDisabled := completeFeatureGates(knownFeatureSets, customFS.Enabled, customFS.Disabled) 48 return newFeatureGate(completeEnabled, completeDisabled) 49 } 50 51 featureSet := knownFeatureSets[fs] 52 53 completeEnabled, completeDisabled := completeFeatureGates(knownFeatureSets, toFeatureGateNames(featureSet.Enabled), toFeatureGateNames(featureSet.Disabled)) 54 return newFeatureGate(completeEnabled, completeDisabled) 55 } 56 57 // GenerateCustomFeatures generates the custom feature gates from the install config. 58 func GenerateCustomFeatures(features []string) *configv1.CustomFeatureGates { 59 customFeatures := &configv1.CustomFeatureGates{} 60 61 for _, feature := range features { 62 featureName, enabled := parseCustomFeatureGate(feature) 63 64 if enabled { 65 customFeatures.Enabled = append(customFeatures.Enabled, featureName) 66 } else { 67 customFeatures.Disabled = append(customFeatures.Disabled, featureName) 68 } 69 } 70 71 return customFeatures 72 } 73 74 // parseCustomFeatureGates parses the custom feature gate string into the feature name and whether it is enabled. 75 // The expected format is <FeatureName>=<Enabled>. 76 func parseCustomFeatureGate(rawFeature string) (configv1.FeatureGateName, bool) { 77 var featureName string 78 var enabled bool 79 80 featureParts := strings.Split(rawFeature, "=") 81 if len(featureParts) != 2 { 82 return "", false 83 } 84 85 featureName = featureParts[0] 86 87 var err error 88 enabled, err = strconv.ParseBool(featureParts[1]) 89 if err != nil { 90 return "", false 91 } 92 93 return configv1.FeatureGateName(featureName), enabled 94 }