Skip to content

Commit 3415217

Browse files
Merge pull request #1269 from theobarberbany/vsphere-featuregating
OCPCLOUD-2565: Updates vsphere feature gates
2 parents a1c30a8 + 406a932 commit 3415217

File tree

232 files changed

+7693
-6028
lines changed

Some content is hidden

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

232 files changed

+7693
-6028
lines changed

cmd/vsphere/main.go

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package main
22

33
import (
4-
"context"
54
"flag"
65
"fmt"
76
"os"
7+
"strings"
88
"time"
99

1010
configv1 "github.com/openshift/api/config/v1"
1111
apifeatures "github.com/openshift/api/features"
1212
machinev1 "github.com/openshift/api/machine/v1beta1"
13-
configv1client "github.com/openshift/client-go/config/clientset/versioned"
14-
configinformers "github.com/openshift/client-go/config/informers/externalversions"
1513
"github.com/openshift/library-go/pkg/config/leaderelection"
16-
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
17-
"github.com/openshift/library-go/pkg/operator/events"
14+
"github.com/openshift/library-go/pkg/features"
1815
capimachine "github.com/openshift/machine-api-operator/pkg/controller/machine"
1916
"github.com/openshift/machine-api-operator/pkg/controller/vsphere"
2017
machine "github.com/openshift/machine-api-operator/pkg/controller/vsphere"
@@ -23,6 +20,9 @@ import (
2320
"github.com/openshift/machine-api-operator/pkg/util"
2421
"github.com/openshift/machine-api-operator/pkg/version"
2522
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apiserver/pkg/util/feature"
24+
k8sflag "k8s.io/component-base/cli/flag"
25+
"k8s.io/component-base/featuregate"
2626
"k8s.io/klog/v2"
2727
"k8s.io/klog/v2/textlogger"
2828
ipamv1beta1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1"
@@ -35,6 +35,8 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3636
)
3737

38+
const timeout = 10 * time.Minute
39+
3840
func main() {
3941
var printVersion bool
4042
flag.BoolVar(&printVersion, "version", false, "print version and exit")
@@ -90,6 +92,18 @@ func main() {
9092
":9440",
9193
"The address for health checking.",
9294
)
95+
96+
// Sets up feature gates
97+
defaultMutableGate := feature.DefaultMutableFeatureGate
98+
_, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
99+
if err != nil {
100+
klog.Fatalf("Error setting up feature gates: %v", err)
101+
}
102+
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"))
106+
93107
flag.Parse()
94108

95109
if logToStderr != nil {
@@ -102,7 +116,7 @@ func main() {
102116
}
103117

104118
cfg := config.GetConfigOrDie()
105-
syncPeriod := 10 * time.Minute
119+
syncPeriod := timeout
106120

107121
le := util.GetLeaderElectionConfig(cfg, configv1.LeaderElection{
108122
Disable: !*leaderElect,
@@ -132,6 +146,17 @@ func main() {
132146
klog.Infof("Watching machine-api objects only in namespace %q for reconciliation.", *watchNamespace)
133147
}
134148

149+
// Sets feature gates from flags
150+
klog.Infof("Initializing feature gates: %s", strings.Join(defaultMutableGate.KnownFeatures(), ", "))
151+
err = defaultMutableGate.SetFromMap(featureGateArgs)
152+
if err != nil {
153+
klog.Fatalf("Error setting feature gates from flags: %v", err)
154+
}
155+
klog.Infof("FeatureGateMachineAPIMigration initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateMachineAPIMigration)))
156+
157+
staticIPFeatureGateEnabled := defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateVSphereStaticIPs))
158+
klog.Infof("FeatureGateVSphereStaticIPs initialised: %t", staticIPFeatureGateEnabled)
159+
135160
// Setup a Manager
136161
mgr, err := manager.New(cfg, opts)
137162
if err != nil {
@@ -142,41 +167,6 @@ func main() {
142167
// network error or stale cache.
143168
taskIDCache := make(map[string]string)
144169

145-
desiredVersion := getReleaseVersion()
146-
missingVersion := "0.0.1-snapshot"
147-
148-
configClient, err := configv1client.NewForConfig(mgr.GetConfig())
149-
if err != nil {
150-
klog.Fatal(err, "unable to create config client")
151-
os.Exit(1)
152-
}
153-
configInformers := configinformers.NewSharedInformerFactory(configClient, 10*time.Minute)
154-
155-
// By default, this will exit(0) if the featuregates change
156-
featureGateAccessor := featuregates.NewFeatureGateAccess(
157-
desiredVersion, missingVersion,
158-
configInformers.Config().V1().ClusterVersions(),
159-
configInformers.Config().V1().FeatureGates(),
160-
events.NewLoggingEventRecorder("vspherecontroller"),
161-
)
162-
go featureGateAccessor.Run(context.Background())
163-
go configInformers.Start(context.Background().Done())
164-
165-
select {
166-
case <-featureGateAccessor.InitialFeatureGatesObserved():
167-
featureGates, _ := featureGateAccessor.CurrentFeatureGates()
168-
klog.Infof("FeatureGates initialized: %v", featureGates.KnownFeatures())
169-
case <-time.After(1 * time.Minute):
170-
klog.Fatal("timed out waiting for FeatureGate detection")
171-
}
172-
173-
featureGates, err := featureGateAccessor.CurrentFeatureGates()
174-
if err != nil {
175-
klog.Fatalf("unable to retrieve current feature gates: %v", err)
176-
}
177-
// read featuregate read and usage to set a variable to pass to a controller
178-
staticIPFeatureGateEnabled := featureGates.Enabled(apifeatures.FeatureGateVSphereStaticIPs)
179-
180170
// Initialize machine actuator.
181171
machineActuator := machine.NewActuator(machine.ActuatorParams{
182172
Client: mgr.GetClient(),
@@ -228,11 +218,3 @@ func main() {
228218
klog.Fatalf("Failed to run manager: %v", err)
229219
}
230220
}
231-
232-
func getReleaseVersion() string {
233-
releaseVersion := os.Getenv("RELEASE_VERSION")
234-
if len(releaseVersion) == 0 {
235-
return "0.0.1-snapshot"
236-
}
237-
return releaseVersion
238-
}

go.mod

Lines changed: 3 additions & 4 deletions
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-20240116081341-964bcb3f545c
15+
github.com/openshift/library-go v0.0.0-20240723172506-8bb8fe6cc56d
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
@@ -37,6 +37,7 @@ require (
3737
require (
3838
github.com/golangci/golangci-lint v1.52.2
3939
golang.org/x/time v0.5.0
40+
k8s.io/component-base v0.30.1
4041
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96
4142
)
4243

@@ -84,7 +85,6 @@ require (
8485
github.com/firefart/nonamedreturns v1.0.4 // indirect
8586
github.com/fsnotify/fsnotify v1.7.0 // indirect
8687
github.com/fzipp/gocyclo v0.6.0 // indirect
87-
github.com/ghodss/yaml v1.0.0 // indirect
8888
github.com/go-critic/go-critic v0.7.0 // indirect
8989
github.com/go-errors/errors v1.4.2 // indirect
9090
github.com/go-logr/zapr v1.3.0 // indirect
@@ -255,8 +255,7 @@ require (
255255
honnef.co/go/tools v0.4.3 // indirect
256256
k8s.io/apiextensions-apiserver v0.30.1 // indirect
257257
k8s.io/cli-runtime v0.30.0 // indirect
258-
k8s.io/component-base v0.30.1 // indirect
259-
k8s.io/kube-aggregator v0.29.0 // indirect
258+
k8s.io/kube-aggregator v0.30.1 // indirect
260259
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
261260
mvdan.cc/gofumpt v0.4.0 // indirect
262261
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
158158
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
159159
github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo=
160160
github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
161-
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
162-
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
163161
github.com/go-critic/go-critic v0.7.0 h1:tqbKzB8pqi0NsRZ+1pyU4aweAF7A7QN0Pi4Q02+rYnQ=
164162
github.com/go-critic/go-critic v0.7.0/go.mod h1:moYzd7GdVXE2C2hYTwd7h0CPcqlUeclsyBRwMa38v64=
165163
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
@@ -480,8 +478,8 @@ github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215 h1:NY9X6aNRa3PKTRj9n
480478
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
481479
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 h1:JtLhaGpSEconE+1IKmIgCOof/Len5ceG6H1pk43yv5U=
482480
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87/go.mod h1:3IPD4U0qyovZS4EFady2kqY32m8lGcbs/Wx+yprg9z8=
483-
github.com/openshift/library-go v0.0.0-20240116081341-964bcb3f545c h1:gLylEQQryG+A6nqWYIwE1wUzn1eFUmthjADvflMWKnM=
484-
github.com/openshift/library-go v0.0.0-20240116081341-964bcb3f545c/go.mod h1:82B0gt8XawdXWRtKMrm3jSMTeRsiOSYKCi4F0fvPjG0=
481+
github.com/openshift/library-go v0.0.0-20240723172506-8bb8fe6cc56d h1:smjzDkp2p3wbZfn9W4+RivdoNqJm2ESmPemUyU237KU=
482+
github.com/openshift/library-go v0.0.0-20240723172506-8bb8fe6cc56d/go.mod h1:PdASVamWinll2BPxiUpXajTwZxV8A1pQbWEsCN1od7I=
485483
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
486484
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
487485
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
@@ -1124,8 +1122,8 @@ k8s.io/component-base v0.30.1 h1:bvAtlPh1UrdaZL20D9+sWxsJljMi0QZ3Lmw+kmZAaxQ=
11241122
k8s.io/component-base v0.30.1/go.mod h1:e/X9kDiOebwlI41AvBHuWdqFriSRrX50CdwA9TFaHLI=
11251123
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
11261124
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
1127-
k8s.io/kube-aggregator v0.29.0 h1:N4fmtePxOZ+bwiK1RhVEztOU+gkoVkvterHgpwAuiTw=
1128-
k8s.io/kube-aggregator v0.29.0/go.mod h1:bjatII63ORkFg5yUFP2qm2OC49R0wwxZhRVIyJ4Z4X0=
1125+
k8s.io/kube-aggregator v0.30.1 h1:ymR2BsxDacTKwzKTuNhGZttuk009c+oZbSeD+IPX5q4=
1126+
k8s.io/kube-aggregator v0.30.1/go.mod h1:SFbqWsM6ea8dHd3mPLsZFzJHbjBOS5ykIgJh4znZ5iQ=
11291127
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
11301128
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
11311129
k8s.io/kubectl v0.30.0 h1:xbPvzagbJ6RNYVMVuiHArC1grrV5vSmmIcSZuCdzRyk=

tools/vendor/github.com/go-logr/logr/README.md

Lines changed: 125 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/vendor/github.com/go-logr/logr/SECURITY.md

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)