@@ -66,6 +66,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
66
66
if err != nil {
67
67
return err
68
68
}
69
+ configInformers := configv1informers .NewSharedInformerFactory (configClient , 10 * time .Minute )
69
70
70
71
operatorClient , err := operatorv1client .NewForConfig (controller .KubeConfig )
71
72
if err != nil {
@@ -83,52 +84,45 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
83
84
return err
84
85
}
85
86
86
- desiredVersion := config . OperatorReleaseVersion
87
+ desiredVersion := os . Getenv ( "RELEASE_VERSION" )
87
88
missingVersion := "0.0.1-snapshot"
88
89
89
90
// By default, this will exit(0) the process if the featuregates ever change to a different set of values.
90
91
featureGateAccessor := featuregates .NewFeatureGateAccess (
91
92
desiredVersion , missingVersion ,
92
93
configInformers .Config ().V1 ().ClusterVersions (), configInformers .Config ().V1 ().FeatureGates (),
93
- eventRecorder ,
94
+ controller . EventRecorder ,
94
95
)
95
96
go featureGateAccessor .Run (ctx )
96
- go configInformers .Start (config . Stop )
97
+ go configInformers .Start (ctx . Done () )
97
98
98
99
select {
99
100
case <- featureGateAccessor .InitialFeatureGatesObserved ():
100
101
featureGates , _ := featureGateAccessor .CurrentFeatureGates ()
101
- log . Info ("FeatureGates initialized" , "knownFeatures " , featureGates .KnownFeatures ())
102
+ klog . Infof ("FeatureGates initialized: knownFeatureGates=%v " , featureGates .KnownFeatures ())
102
103
case <- time .After (1 * time .Minute ):
103
- log . Error ( nil , "timed out waiting for FeatureGate detection" )
104
- return nil , fmt .Errorf ("timed out waiting for FeatureGate detection" )
104
+ klog . Errorf ( "timed out waiting for FeatureGate detection" )
105
+ return fmt .Errorf ("timed out waiting for FeatureGate detection" )
105
106
}
106
107
107
108
featureGates , err := featureGateAccessor .CurrentFeatureGates ()
108
109
if err != nil {
109
- return nil , err
110
+ return err
110
111
}
111
- // example of future featuregate read and usage to set a variable to pass to a controller
112
- gatewayAPIEnabled := featureGates .Enabled (configv1 .FeatureGateGatewayAPI )
112
+ insightsConfigAPIEnabled := featureGates .Enabled (v1 .FeatureGateInsightsConfigAPI )
113
113
114
114
// ensure the insight snapshot directory exists
115
115
if _ , err = os .Stat (s .StoragePath ); err != nil && os .IsNotExist (err ) {
116
116
if err = os .MkdirAll (s .StoragePath , 0777 ); err != nil {
117
117
return fmt .Errorf ("can't create --path: %v" , err )
118
118
}
119
119
}
120
- tpEnabled , err := isTechPreviewEnabled (ctx , configClient )
121
- if err != nil {
122
- klog .Error ("can't read cluster feature gates: %v" , err )
123
- }
124
120
var apiConfigObserver configobserver.APIConfigObserver
125
- if tpEnabled {
126
- configInformers := configv1informers .NewSharedInformerFactory (configClient , 10 * time .Minute )
121
+ if insightsConfigAPIEnabled {
127
122
apiConfigObserver , err = configobserver .NewAPIConfigObserver (gatherKubeConfig , controller .EventRecorder , configInformers )
128
123
if err != nil {
129
124
return err
130
125
}
131
- configInformers .Start (ctx .Done ())
132
126
go apiConfigObserver .Run (ctx , 1 )
133
127
}
134
128
@@ -180,7 +174,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
180
174
initialCheckTimeout := s .Controller .Interval / 24
181
175
initialCheckInterval := 20 * time .Second
182
176
baseInitialDelay := s .Controller .Interval / 12
183
- err = wait .PollImmediate ( initialCheckInterval , wait .Jitter (initialCheckTimeout , 0.1 ), isRunning ( ctx , gatherKubeConfig ))
177
+ err = wait .PollUntilContextTimeout ( ctx , initialCheckInterval , wait .Jitter (initialCheckTimeout , 0.1 ), true , isRunning ( gatherKubeConfig ))
184
178
if err != nil {
185
179
initialDelay = wait .Jitter (baseInitialDelay , 0.5 )
186
180
klog .Infof ("Unable to check insights-operator pod status. Setting initial delay to %s" , initialDelay )
@@ -221,8 +215,8 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
221
215
return nil
222
216
}
223
217
224
- func isRunning (ctx context. Context , kubeConfig * rest.Config ) wait.ConditionFunc {
225
- return func () (bool , error ) {
218
+ func isRunning (kubeConfig * rest.Config ) wait.ConditionWithContextFunc {
219
+ return func (ctx context. Context ) (bool , error ) {
226
220
c , err := corev1client .NewForConfig (kubeConfig )
227
221
if err != nil {
228
222
return false , err
@@ -258,12 +252,3 @@ func initiateSCAController(ctx context.Context,
258
252
scaController := sca .New (ctx , kubeClient .CoreV1 (), configObserver , insightsClient )
259
253
return scaController
260
254
}
261
-
262
- // featureEnabled checks if the feature is enabled in the "cluster" FeatureGate
263
- func isTechPreviewEnabled (ctx context.Context , client * configv1client.Clientset ) (bool , error ) {
264
- fg , err := client .ConfigV1 ().FeatureGates ().Get (ctx , "cluster" , metav1.GetOptions {})
265
- if err != nil {
266
- return false , err
267
- }
268
- return fg .Spec .FeatureSet == v1 .TechPreviewNoUpgrade , nil
269
- }
0 commit comments