Skip to content

Commit 5bb985f

Browse files
Merge pull request #117 from theobarberbany/featuregate-impl
OCPCLOUD-2565: Featuregate implementation
2 parents d69a3e3 + a55b4ea commit 5bb985f

File tree

988 files changed

+1692
-194503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

988 files changed

+1692
-194503
lines changed

cmd/manager/main.go

Lines changed: 27 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,23 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"context"
2120
"flag"
22-
"fmt"
2321
"os"
22+
"strings"
2423
"time"
2524

2625
configv1 "github.com/openshift/api/config/v1"
2726
apifeatures "github.com/openshift/api/features"
2827
machinev1 "github.com/openshift/api/machine/v1beta1"
29-
configclient "github.com/openshift/client-go/config/clientset/versioned"
30-
configinformers "github.com/openshift/client-go/config/informers/externalversions"
31-
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
32-
"github.com/openshift/library-go/pkg/operator/events"
28+
"github.com/openshift/library-go/pkg/features"
3329
"github.com/openshift/machine-api-operator/pkg/controller/machine"
3430
"github.com/openshift/machine-api-operator/pkg/metrics"
3531
actuator "github.com/openshift/machine-api-provider-azure/pkg/cloud/azure/actuators/machine"
3632
machinesetcontroller "github.com/openshift/machine-api-provider-azure/pkg/cloud/azure/actuators/machineset"
3733
"github.com/openshift/machine-api-provider-azure/pkg/cloud/azure/services/resourceskus"
3834
"github.com/openshift/machine-api-provider-azure/pkg/record"
39-
corev1 "k8s.io/api/core/v1"
40-
"k8s.io/client-go/kubernetes"
41-
"k8s.io/client-go/rest"
42-
k8sflag "k8s.io/component-base/cli/flag"
35+
"k8s.io/apiserver/pkg/util/feature"
36+
"k8s.io/component-base/featuregate"
4337
"k8s.io/klog/v2"
4438
"k8s.io/klog/v2/klogr"
4539
ctrl "sigs.k8s.io/controller-runtime"
@@ -100,9 +94,15 @@ func main() {
10094
1,
10195
"Maximum number of concurrent reconciles per controller instance.",
10296
)
97+
// Sets up feature gates
98+
defaultMutableGate := feature.DefaultMutableFeatureGate
99+
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateAzureWorkloadIdentity, apifeatures.FeatureGateMachineAPIMigration)
100+
if err != nil {
101+
klog.Fatalf("Error setting up feature gates: %v", err)
102+
}
103103

104-
featureGateArgs := map[string]bool{}
105-
flag.Var(k8sflag.NewMapStringBool(&featureGateArgs), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimen")
104+
// Add the --feature-gates flag
105+
gateOpts.AddFlagsToGoFlagSet(nil)
106106

107107
klog.InitFlags(nil)
108108
flag.Set("logtostderr", "true")
@@ -135,6 +135,20 @@ func main() {
135135
klog.Infof("Watching machine-api objects only in namespace %q for reconciliation.", *watchNamespace)
136136
}
137137

138+
// Sets feature gates from flags
139+
klog.Infof("Initializing feature gates: %s", strings.Join(defaultMutableGate.KnownFeatures(), ", "))
140+
warnings, err := gateOpts.ApplyTo(defaultMutableGate)
141+
if err != nil {
142+
klog.Fatalf("Error setting feature gates from flags: %v", err)
143+
}
144+
if len(warnings) > 0 {
145+
klog.Infof("Warnings setting feature gates from flags: %v", warnings)
146+
}
147+
148+
klog.Infof("FeatureGateMachineAPIMigration initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateMachineAPIMigration)))
149+
klog.Infof("FeatureGateAzureWorkloadIdentity initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateAzureWorkloadIdentity)))
150+
azureWorkloadIdentityEnabled := defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateAzureWorkloadIdentity))
151+
138152
// Setup a Manager
139153
mgr, err := manager.New(cfg, opts)
140154
if err != nil {
@@ -143,31 +157,8 @@ func main() {
143157

144158
// Initialize event recorder.
145159
record.InitFromRecorder(mgr.GetEventRecorderFor("azure-controller"))
146-
147160
stopSignalContext := ctrl.SetupSignalHandler()
148161

149-
featureGateAccessor, err := createFeatureGateAccessor(
150-
context.Background(),
151-
cfg,
152-
"machine-api-provider-azure",
153-
"openshift-machine-api",
154-
"machine-api-controllers",
155-
getReleaseVersion(),
156-
"0.0.1-snapshot",
157-
syncPeriod,
158-
stopSignalContext.Done(),
159-
)
160-
if err != nil {
161-
klog.Fatalf("Failed to create feature gate accessor: %v", err)
162-
}
163-
164-
featureGates, err := awaitEnabledFeatureGates(featureGateAccessor, 1*time.Minute)
165-
if err != nil {
166-
klog.Fatalf("Failed to get feature gates: %v", err)
167-
}
168-
169-
azureWorkloadIdentityEnabled := featureGates.Enabled(apifeatures.FeatureGateAzureWorkloadIdentity)
170-
171162
// Initialize machine actuator.
172163
machineActuator := actuator.NewActuator(actuator.ActuatorParams{
173164
CoreClient: mgr.GetClient(),
@@ -186,7 +177,7 @@ func main() {
186177

187178
if err := machine.AddWithActuatorOpts(mgr, machineActuator, controller.Options{
188179
MaxConcurrentReconciles: *maxConcurrentReconciles,
189-
}); err != nil {
180+
}, defaultMutableGate); err != nil {
190181
klog.Fatal(err)
191182
}
192183

@@ -215,62 +206,3 @@ func main() {
215206
klog.Fatalf("Failed to run manager: %v", err)
216207
}
217208
}
218-
219-
func createFeatureGateAccessor(ctx context.Context, cfg *rest.Config, operatorName, deploymentNamespace, deploymentName, desiredVersion, missingVersion string, syncPeriod time.Duration, stop <-chan struct{}) (featuregates.FeatureGateAccess, error) {
220-
ctx, cancelFn := context.WithCancel(ctx)
221-
go func() {
222-
defer cancelFn()
223-
<-stop
224-
}()
225-
226-
kubeClient, err := kubernetes.NewForConfig(cfg)
227-
if err != nil {
228-
return nil, fmt.Errorf("failed to create kube client: %w", err)
229-
}
230-
231-
eventRecorder := events.NewKubeRecorder(kubeClient.CoreV1().Events(deploymentNamespace), operatorName, &corev1.ObjectReference{
232-
APIVersion: "apps/v1",
233-
Kind: "Deployment",
234-
Namespace: deploymentNamespace,
235-
Name: deploymentName,
236-
})
237-
238-
configClient, err := configclient.NewForConfig(cfg)
239-
if err != nil {
240-
return nil, fmt.Errorf("failed to create config client: %w", err)
241-
}
242-
configInformers := configinformers.NewSharedInformerFactory(configClient, syncPeriod)
243-
244-
featureGateAccessor := featuregates.NewFeatureGateAccess(
245-
desiredVersion, missingVersion,
246-
configInformers.Config().V1().ClusterVersions(), configInformers.Config().V1().FeatureGates(),
247-
eventRecorder,
248-
)
249-
go featureGateAccessor.Run(ctx)
250-
go configInformers.Start(stop)
251-
252-
return featureGateAccessor, nil
253-
}
254-
255-
func awaitEnabledFeatureGates(accessor featuregates.FeatureGateAccess, timeout time.Duration) (featuregates.FeatureGate, error) {
256-
select {
257-
case <-accessor.InitialFeatureGatesObserved():
258-
featureGates, err := accessor.CurrentFeatureGates()
259-
if err != nil {
260-
return nil, err
261-
} else {
262-
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())
263-
return featureGates, nil
264-
}
265-
case <-time.After(timeout):
266-
return nil, fmt.Errorf("timed out waiting for FeatureGate detection")
267-
}
268-
}
269-
270-
func getReleaseVersion() string {
271-
releaseVersion := os.Getenv("RELEASE_VERSION")
272-
if len(releaseVersion) == 0 {
273-
return "0.0.1-snapshot"
274-
}
275-
return releaseVersion
276-
}

go.mod

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ require (
1616
github.com/mitchellh/mapstructure v1.5.0
1717
github.com/onsi/ginkgo/v2 v2.19.0
1818
github.com/onsi/gomega v1.33.1
19-
github.com/openshift/api v0.0.0-20240611134040-5c2b46e4709a
20-
github.com/openshift/machine-api-operator v0.2.1-0.20240606171151-148e5dc759a6
19+
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215
20+
github.com/openshift/machine-api-operator v0.2.1-0.20240813104042-5af274324af8
2121
github.com/pkg/errors v0.9.1
2222
github.com/spf13/cobra v1.8.0
2323
golang.org/x/crypto v0.24.0
@@ -38,9 +38,9 @@ require (
3838
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0
3939
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0
4040
github.com/jongio/azidext/go/azidext v0.5.0
41-
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87
42-
github.com/openshift/library-go v0.0.0-20240607134135-aed018c215a1
41+
github.com/openshift/library-go v0.0.0-20240822162747-42bcbbc4ccc6
4342
go.uber.org/mock v0.4.0
43+
k8s.io/apiserver v0.30.1
4444
k8s.io/component-base v0.30.2
4545
)
4646

@@ -104,13 +104,13 @@ require (
104104
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
105105
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
106106
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
107+
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 // indirect
107108
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
108109
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
109110
github.com/prometheus/client_golang v1.18.0 // indirect
110111
github.com/prometheus/client_model v0.5.0 // indirect
111112
github.com/prometheus/common v0.45.0 // indirect
112113
github.com/prometheus/procfs v0.12.0 // indirect
113-
github.com/robfig/cron v1.2.0 // indirect
114114
github.com/russross/blackfriday/v2 v2.1.0 // indirect
115115
github.com/spf13/afero v1.10.0 // indirect
116116
github.com/spf13/pflag v1.0.5 // indirect
@@ -135,13 +135,10 @@ require (
135135
gopkg.in/yaml.v2 v2.4.0 // indirect
136136
gopkg.in/yaml.v3 v3.0.1 // indirect
137137
k8s.io/apiextensions-apiserver v0.30.1 // indirect
138-
k8s.io/apiserver v0.30.1 // indirect
139138
k8s.io/cli-runtime v0.30.0 // indirect
140-
k8s.io/kube-aggregator v0.30.1 // indirect
141139
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
142140
k8s.io/kubectl v0.30.0 // indirect
143141
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
144-
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 // indirect
145142
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
146143
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
147144
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect

go.sum

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA
297297
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
298298
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
299299
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
300-
github.com/openshift/api v0.0.0-20240611134040-5c2b46e4709a h1:Q8D8zVvF0eKZt+Zz7ZaLmp9e8A0ZBPej1WJdTHTrIEQ=
301-
github.com/openshift/api v0.0.0-20240611134040-5c2b46e4709a/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
300+
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215 h1:NY9X6aNRa3PKTRj9nTncCoGRbdwiis2CL1T3miXxjoc=
301+
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
302302
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 h1:JtLhaGpSEconE+1IKmIgCOof/Len5ceG6H1pk43yv5U=
303303
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87/go.mod h1:3IPD4U0qyovZS4EFady2kqY32m8lGcbs/Wx+yprg9z8=
304-
github.com/openshift/library-go v0.0.0-20240607134135-aed018c215a1 h1:jLERUXwvYY9+9oCz66oQ/XTZzeyH8RmCpxiImYVYnmA=
305-
github.com/openshift/library-go v0.0.0-20240607134135-aed018c215a1/go.mod h1:PdASVamWinll2BPxiUpXajTwZxV8A1pQbWEsCN1od7I=
306-
github.com/openshift/machine-api-operator v0.2.1-0.20240606171151-148e5dc759a6 h1:6vLe4UmLrTqPlQGa1Twh/6a72CUjtURighALQ2CBKE0=
307-
github.com/openshift/machine-api-operator v0.2.1-0.20240606171151-148e5dc759a6/go.mod h1:1wkCDl8IVwAsen4F5xvM9uvOXj7yhfQ6BzzEVAVTXsA=
304+
github.com/openshift/library-go v0.0.0-20240822162747-42bcbbc4ccc6 h1:SXoVbgBF/K2BadaF+e0ubOkyFDlu+/MwRZ/BhifoQE4=
305+
github.com/openshift/library-go v0.0.0-20240822162747-42bcbbc4ccc6/go.mod h1:PdASVamWinll2BPxiUpXajTwZxV8A1pQbWEsCN1od7I=
306+
github.com/openshift/machine-api-operator v0.2.1-0.20240813104042-5af274324af8 h1:yPtRlkjfyH1zVa49PxglUki9TgJ02XtDR8xefGEfTAg=
307+
github.com/openshift/machine-api-operator v0.2.1-0.20240813104042-5af274324af8/go.mod h1:ntS+1b2WpwGffLBuV8rS2zSndDIDtTPZcaBONrkaqrM=
308308
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
309309
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
310310
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
@@ -324,8 +324,6 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne
324324
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
325325
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
326326
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
327-
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
328-
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
329327
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
330328
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
331329
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
@@ -752,8 +750,6 @@ k8s.io/component-base v0.30.2 h1:pqGBczYoW1sno8q9ObExUqrYSKhtE5rW3y6gX88GZII=
752750
k8s.io/component-base v0.30.2/go.mod h1:yQLkQDrkK8J6NtP+MGJOws+/PPeEXNpwFixsUI7h/OE=
753751
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
754752
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
755-
k8s.io/kube-aggregator v0.30.1 h1:ymR2BsxDacTKwzKTuNhGZttuk009c+oZbSeD+IPX5q4=
756-
k8s.io/kube-aggregator v0.30.1/go.mod h1:SFbqWsM6ea8dHd3mPLsZFzJHbjBOS5ykIgJh4znZ5iQ=
757753
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
758754
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
759755
k8s.io/kubectl v0.30.0 h1:xbPvzagbJ6RNYVMVuiHArC1grrV5vSmmIcSZuCdzRyk=
@@ -771,8 +767,6 @@ sigs.k8s.io/controller-tools v0.15.0 h1:4dxdABXGDhIa68Fiwaif0vcu32xfwmgQ+w8p+5Cx
771767
sigs.k8s.io/controller-tools v0.15.0/go.mod h1:8zUSS2T8Hx0APCNRhJWbS3CAQEbIxLa07khzh7pZmXM=
772768
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
773769
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
774-
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 h1:PFWFSkpArPNJxFX4ZKWAk9NSeRoZaXschn+ULa4xVek=
775-
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96/go.mod h1:EOBQyBowOUsd7U4CJnMHNE0ri+zCXyouGdLwC/jZU+I=
776770
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 h1:XX3Ajgzov2RKUdc5jW3t5jwY7Bo7dcRm+tFxT+NfgY0=
777771
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3/go.mod h1:9n16EZKMhXBNSiUC5kSdFQJkdH3zbxS/JoO619G1VAY=
778772
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 h1:W6cLQc5pnqM7vh3b7HvGNfXrJ/xL6BDMS0v1V/HHg5U=

vendor/github.com/openshift/api/.ci-operator.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

vendor/github.com/openshift/api/.gitattributes

Lines changed: 0 additions & 7 deletions
This file was deleted.

vendor/github.com/openshift/api/.gitignore

Lines changed: 0 additions & 21 deletions
This file was deleted.

vendor/github.com/openshift/api/Dockerfile.rhel8

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)