Skip to content

Commit 14da559

Browse files
Merge pull request #1275 from theobarberbany/operator-pass-feature-gate-flag-machine
OCPCLOUD-2565: Updates operator to pass feature gates flags to Machine controllers
2 parents be91cb3 + ef5c2ef commit 14da559

File tree

25 files changed

+285
-292
lines changed

25 files changed

+285
-292
lines changed

cmd/machineset/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
machinev1 "github.com/openshift/api/machine/v1beta1"
2929
mapiwebhooks "github.com/openshift/machine-api-operator/pkg/webhooks"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31-
k8sflag "k8s.io/component-base/cli/flag"
3231
ctrl "sigs.k8s.io/controller-runtime"
3332

3433
"github.com/openshift/library-go/pkg/config/leaderelection"
@@ -111,14 +110,13 @@ func main() {
111110

112111
// Sets up feature gates
113112
defaultMutableGate := feature.DefaultMutableFeatureGate
114-
_, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
113+
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
115114
if err != nil {
116115
klog.Fatalf("Error setting up feature gates: %v", err)
117116
}
118117

119-
featureGateArgs := map[string]bool{}
120-
flag.Var(k8sflag.NewMapStringBool(&featureGateArgs), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
121-
"Options are:\n"+strings.Join(defaultMutableGate.KnownFeatures(), "\n"))
118+
// Add the --feature-gates flag
119+
gateOpts.AddFlagsToGoFlagSet(nil)
122120

123121
flag.Parse()
124122
if *watchNamespace != "" {
@@ -172,10 +170,14 @@ func main() {
172170

173171
// Sets feature gates from flags
174172
klog.Infof("Initializing feature gates: %s", strings.Join(defaultMutableGate.KnownFeatures(), ", "))
175-
err = defaultMutableGate.SetFromMap(featureGateArgs)
173+
warnings, err := gateOpts.ApplyTo(defaultMutableGate)
176174
if err != nil {
177175
klog.Fatalf("Error setting feature gates from flags: %v", err)
178176
}
177+
if len(warnings) > 0 {
178+
klog.Infof("Warnings setting feature gates from flags: %v", warnings)
179+
}
180+
179181
klog.Infof("FeatureGateMachineAPIMigration initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateMachineAPIMigration)))
180182

181183
// Enable defaulting and validating webhooks

cmd/vsphere/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/openshift/machine-api-operator/pkg/version"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apiserver/pkg/util/feature"
24-
k8sflag "k8s.io/component-base/cli/flag"
2524
"k8s.io/component-base/featuregate"
2625
"k8s.io/klog/v2"
2726
"k8s.io/klog/v2/textlogger"
@@ -95,14 +94,13 @@ func main() {
9594

9695
// Sets up feature gates
9796
defaultMutableGate := feature.DefaultMutableFeatureGate
98-
_, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
97+
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
9998
if err != nil {
10099
klog.Fatalf("Error setting up feature gates: %v", err)
101100
}
102101

103-
featureGateArgs := map[string]bool{}
104-
flag.Var(k8sflag.NewMapStringBool(&featureGateArgs), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
105-
"Options are:\n"+strings.Join(defaultMutableGate.KnownFeatures(), "\n"))
102+
// Add the --feature-gates flag
103+
gateOpts.AddFlagsToGoFlagSet(nil)
106104

107105
flag.Parse()
108106

@@ -148,10 +146,14 @@ func main() {
148146

149147
// Sets feature gates from flags
150148
klog.Infof("Initializing feature gates: %s", strings.Join(defaultMutableGate.KnownFeatures(), ", "))
151-
err = defaultMutableGate.SetFromMap(featureGateArgs)
149+
warnings, err := gateOpts.ApplyTo(defaultMutableGate)
152150
if err != nil {
153151
klog.Fatalf("Error setting feature gates from flags: %v", err)
154152
}
153+
if len(warnings) > 0 {
154+
klog.Infof("Warnings setting feature gates from flags: %v", warnings)
155+
}
156+
155157
klog.Infof("FeatureGateMachineAPIMigration initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateMachineAPIMigration)))
156158

157159
staticIPFeatureGateEnabled := defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateVSphereStaticIPs))

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/onsi/gomega v1.32.0
1313
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215
1414
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87
15-
github.com/openshift/library-go v0.0.0-20240723172506-8bb8fe6cc56d
15+
github.com/openshift/library-go v0.0.0-20240822162747-42bcbbc4ccc6
1616
github.com/prometheus/client_golang v1.18.0
1717
github.com/spf13/cobra v1.8.0
1818
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 h1:JtLhaGpSEco
484484
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87/go.mod h1:3IPD4U0qyovZS4EFady2kqY32m8lGcbs/Wx+yprg9z8=
485485
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20240626103413-ddea9c7c0aca h1:HFFzJznFQVudyVSpMa+hZwXZpc0ZvFCIpiMNFdf21g8=
486486
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20240626103413-ddea9c7c0aca/go.mod h1:osVq9/R6qKHBQxDP4cYTvkgXVBKOMs1SOfPLFfn0m7A=
487-
github.com/openshift/library-go v0.0.0-20240723172506-8bb8fe6cc56d h1:smjzDkp2p3wbZfn9W4+RivdoNqJm2ESmPemUyU237KU=
488-
github.com/openshift/library-go v0.0.0-20240723172506-8bb8fe6cc56d/go.mod h1:PdASVamWinll2BPxiUpXajTwZxV8A1pQbWEsCN1od7I=
487+
github.com/openshift/library-go v0.0.0-20240822162747-42bcbbc4ccc6 h1:SXoVbgBF/K2BadaF+e0ubOkyFDlu+/MwRZ/BhifoQE4=
488+
github.com/openshift/library-go v0.0.0-20240822162747-42bcbbc4ccc6/go.mod h1:PdASVamWinll2BPxiUpXajTwZxV8A1pQbWEsCN1od7I=
489489
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
490490
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
491491
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=

pkg/operator/operator.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,14 @@ func (optr *Operator) maoConfigFromInfrastructure() (*OperatorConfig, error) {
468468
mhcImage = ""
469469
}
470470

471-
// Given we only support the MachineAPIMigration featuregate being passed by
472-
// flags, it shold be the only thing populated our map (and therefore passed
471+
// Given we only support a handful of featuregates being passed by
472+
// flags, we selectively populate the map (and therefore passed
473473
// as args)
474474
features := map[string]bool{
475-
string(apifeatures.FeatureGateMachineAPIMigration): featureGates.Enabled(apifeatures.FeatureGateMachineAPIMigration),
475+
string(apifeatures.FeatureGateMachineAPIMigration): featureGates.Enabled(apifeatures.FeatureGateMachineAPIMigration),
476+
string(apifeatures.FeatureGateVSphereStaticIPs): featureGates.Enabled(apifeatures.FeatureGateVSphereStaticIPs),
477+
string(apifeatures.FeatureGateGCPLabelsTags): featureGates.Enabled(apifeatures.FeatureGateGCPLabelsTags),
478+
string(apifeatures.FeatureGateAzureWorkloadIdentity): featureGates.Enabled(apifeatures.FeatureGateAzureWorkloadIdentity),
476479
}
477480
if features[string(apifeatures.FeatureGateMachineAPIMigration)] {
478481
klog.V(2).Info("Enabling MachineAPIMigration for provider controller and machinesets")

0 commit comments

Comments
 (0)