1
1
package main
2
2
3
3
import (
4
- "context"
5
4
"flag"
6
5
"fmt"
7
6
"os"
7
+ "strings"
8
8
"time"
9
9
10
10
configv1 "github.com/openshift/api/config/v1"
11
11
apifeatures "github.com/openshift/api/features"
12
12
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"
15
13
"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"
18
15
capimachine "github.com/openshift/machine-api-operator/pkg/controller/machine"
19
16
"github.com/openshift/machine-api-operator/pkg/controller/vsphere"
20
17
machine "github.com/openshift/machine-api-operator/pkg/controller/vsphere"
@@ -23,6 +20,9 @@ import (
23
20
"github.com/openshift/machine-api-operator/pkg/util"
24
21
"github.com/openshift/machine-api-operator/pkg/version"
25
22
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"
26
26
"k8s.io/klog/v2"
27
27
"k8s.io/klog/v2/textlogger"
28
28
ipamv1beta1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1"
@@ -35,6 +35,8 @@ import (
35
35
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
36
36
)
37
37
38
+ const timeout = 10 * time .Minute
39
+
38
40
func main () {
39
41
var printVersion bool
40
42
flag .BoolVar (& printVersion , "version" , false , "print version and exit" )
@@ -90,6 +92,18 @@ func main() {
90
92
":9440" ,
91
93
"The address for health checking." ,
92
94
)
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
+
93
107
flag .Parse ()
94
108
95
109
if logToStderr != nil {
@@ -102,7 +116,7 @@ func main() {
102
116
}
103
117
104
118
cfg := config .GetConfigOrDie ()
105
- syncPeriod := 10 * time . Minute
119
+ syncPeriod := timeout
106
120
107
121
le := util .GetLeaderElectionConfig (cfg , configv1.LeaderElection {
108
122
Disable : ! * leaderElect ,
@@ -132,6 +146,17 @@ func main() {
132
146
klog .Infof ("Watching machine-api objects only in namespace %q for reconciliation." , * watchNamespace )
133
147
}
134
148
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
+
135
160
// Setup a Manager
136
161
mgr , err := manager .New (cfg , opts )
137
162
if err != nil {
@@ -142,41 +167,6 @@ func main() {
142
167
// network error or stale cache.
143
168
taskIDCache := make (map [string ]string )
144
169
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
-
180
170
// Initialize machine actuator.
181
171
machineActuator := machine .NewActuator (machine.ActuatorParams {
182
172
Client : mgr .GetClient (),
@@ -228,11 +218,3 @@ func main() {
228
218
klog .Fatalf ("Failed to run manager: %v" , err )
229
219
}
230
220
}
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
- }
0 commit comments