@@ -17,6 +17,7 @@ limitations under the License.
17
17
package main
18
18
19
19
import (
20
+ "context"
20
21
"errors"
21
22
"flag"
22
23
"fmt"
@@ -57,6 +58,7 @@ import (
57
58
"sigs.k8s.io/cluster-api-provider-aws/exp/instancestate"
58
59
"sigs.k8s.io/cluster-api-provider-aws/feature"
59
60
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/endpoints"
61
+ "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
60
62
"sigs.k8s.io/cluster-api-provider-aws/pkg/record"
61
63
"sigs.k8s.io/cluster-api-provider-aws/version"
62
64
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -183,7 +185,34 @@ func main() {
183
185
os .Exit (1 )
184
186
}
185
187
186
- if err = (& controllers.AWSMachineReconciler {
188
+ setupReconcilersAndWebhooks (ctx , mgr , awsServiceEndpoints , externalResourceGC )
189
+ if feature .Gates .Enabled (feature .EKS ) {
190
+ setupEKSReconcilersAndWebhooks (ctx , mgr , awsServiceEndpoints , externalResourceGC )
191
+ }
192
+
193
+ // +kubebuilder:scaffold:builder
194
+
195
+ if err := mgr .AddReadyzCheck ("webhook" , mgr .GetWebhookServer ().StartedChecker ()); err != nil {
196
+ setupLog .Error (err , "unable to create ready check" )
197
+ os .Exit (1 )
198
+ }
199
+
200
+ if err := mgr .AddHealthzCheck ("webhook" , mgr .GetWebhookServer ().StartedChecker ()); err != nil {
201
+ setupLog .Error (err , "unable to create health check" )
202
+ os .Exit (1 )
203
+ }
204
+
205
+ setupLog .Info ("starting manager" , "version" , version .Get ().String ())
206
+ if err := mgr .Start (ctx ); err != nil {
207
+ setupLog .Error (err , "problem running manager" )
208
+ os .Exit (1 )
209
+ }
210
+ }
211
+
212
+ func setupReconcilersAndWebhooks (ctx context.Context , mgr ctrl.Manager , awsServiceEndpoints []scope.ServiceEndpoint ,
213
+ externalResourceGC bool ,
214
+ ) {
215
+ if err := (& controllers.AWSMachineReconciler {
187
216
Client : mgr .GetClient (),
188
217
Log : ctrl .Log .WithName ("controllers" ).WithName ("AWSMachine" ),
189
218
Recorder : mgr .GetEventRecorderFor ("awsmachine-controller" ),
@@ -193,7 +222,8 @@ func main() {
193
222
setupLog .Error (err , "unable to create controller" , "controller" , "AWSMachine" )
194
223
os .Exit (1 )
195
224
}
196
- if err = (& controllers.AWSClusterReconciler {
225
+
226
+ if err := (& controllers.AWSClusterReconciler {
197
227
Client : mgr .GetClient (),
198
228
Recorder : mgr .GetEventRecorderFor ("awscluster-controller" ),
199
229
Endpoints : awsServiceEndpoints ,
@@ -204,88 +234,6 @@ func main() {
204
234
os .Exit (1 )
205
235
}
206
236
207
- if feature .Gates .Enabled (feature .EKS ) {
208
- setupLog .Info ("enabling EKS controllers and webhooks" )
209
-
210
- if syncPeriod > maxEKSSyncPeriod {
211
- setupLog .Error (errMaxSyncPeriodExceeded , "failed to enable EKS" , "max-sync-period" , maxEKSSyncPeriod , "syn-period" , syncPeriod )
212
- os .Exit (1 )
213
- }
214
-
215
- enableIAM := feature .Gates .Enabled (feature .EKSEnableIAM )
216
- allowAddRoles := feature .Gates .Enabled (feature .EKSAllowAddRoles )
217
- setupLog .V (2 ).Info ("EKS IAM role creation" , "enabled" , enableIAM )
218
- setupLog .V (2 ).Info ("EKS IAM additional roles" , "enabled" , allowAddRoles )
219
- if allowAddRoles && ! enableIAM {
220
- setupLog .Error (errEKSInvalidFlags , "cannot use EKSAllowAddRoles flag without EKSEnableIAM" )
221
- os .Exit (1 )
222
- }
223
-
224
- setupLog .V (2 ).Info ("enabling EKS control plane controller" )
225
- if err := (& ekscontrolplanecontrollers.AWSManagedControlPlaneReconciler {
226
- Client : mgr .GetClient (),
227
- EnableIAM : enableIAM ,
228
- AllowAdditionalRoles : allowAddRoles ,
229
- Endpoints : awsServiceEndpoints ,
230
- WatchFilterValue : watchFilterValue ,
231
- ExternalResourceGC : externalResourceGC ,
232
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
233
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedControlPlane" )
234
- os .Exit (1 )
235
- }
236
-
237
- setupLog .V (2 ).Info ("enabling EKS bootstrap controller" )
238
- if err := (& eksbootstrapcontrollers.EKSConfigReconciler {
239
- Client : mgr .GetClient (),
240
- WatchFilterValue : watchFilterValue ,
241
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
242
- setupLog .Error (err , "unable to create controller" , "controller" , "EKSConfig" )
243
- os .Exit (1 )
244
- }
245
-
246
- if feature .Gates .Enabled (feature .EKSFargate ) {
247
- setupLog .V (2 ).Info ("enabling EKS fargate profile controller" )
248
- if err := (& expcontrollers.AWSFargateProfileReconciler {
249
- Client : mgr .GetClient (),
250
- Recorder : mgr .GetEventRecorderFor ("awsfargateprofile-reconciler" ),
251
- EnableIAM : enableIAM ,
252
- Endpoints : awsServiceEndpoints ,
253
- WatchFilterValue : watchFilterValue ,
254
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
255
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSFargateProfile" )
256
- }
257
-
258
- if err = (& expinfrav1.AWSFargateProfile {}).SetupWebhookWithManager (mgr ); err != nil {
259
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSFargateProfile" )
260
- os .Exit (1 )
261
- }
262
- }
263
-
264
- if feature .Gates .Enabled (feature .MachinePool ) {
265
- setupLog .V (2 ).Info ("enabling EKS managed machine pool controller" )
266
- if err := (& expcontrollers.AWSManagedMachinePoolReconciler {
267
- AllowAdditionalRoles : allowAddRoles ,
268
- Client : mgr .GetClient (),
269
- EnableIAM : enableIAM ,
270
- Endpoints : awsServiceEndpoints ,
271
- Recorder : mgr .GetEventRecorderFor ("awsmanagedmachinepool-reconciler" ),
272
- WatchFilterValue : watchFilterValue ,
273
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
274
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedMachinePool" )
275
- os .Exit (1 )
276
- }
277
-
278
- if err = (& expinfrav1.AWSManagedMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
279
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedMachinePool" )
280
- os .Exit (1 )
281
- }
282
- }
283
-
284
- if err := (& ekscontrolplanev1.AWSManagedControlPlane {}).SetupWebhookWithManager (mgr ); err != nil {
285
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedControlPlane" )
286
- os .Exit (1 )
287
- }
288
- }
289
237
if feature .Gates .Enabled (feature .MachinePool ) {
290
238
setupLog .V (2 ).Info ("enabling machine pool controller and webhook" )
291
239
if err := (& expcontrollers.AWSMachinePoolReconciler {
@@ -297,11 +245,12 @@ func main() {
297
245
os .Exit (1 )
298
246
}
299
247
300
- if err = (& expinfrav1.AWSMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
248
+ if err : = (& expinfrav1.AWSMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
301
249
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachinePool" )
302
250
os .Exit (1 )
303
251
}
304
252
}
253
+
305
254
if feature .Gates .Enabled (feature .EventBridgeInstanceState ) {
306
255
setupLog .Info ("EventBridge notifications enabled. enabling AWSInstanceStateController" )
307
256
if err := (& instancestate.AwsInstanceStateReconciler {
@@ -314,6 +263,7 @@ func main() {
314
263
os .Exit (1 )
315
264
}
316
265
}
266
+
317
267
if feature .Gates .Enabled (feature .AutoControllerIdentityCreator ) {
318
268
setupLog .Info ("AutoControllerIdentityCreator enabled" )
319
269
if err := (& controlleridentitycreator.AWSControllerIdentityReconciler {
@@ -327,50 +277,117 @@ func main() {
327
277
}
328
278
}
329
279
330
- if err = (& infrav1.AWSMachineTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
280
+ if err : = (& infrav1.AWSMachineTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
331
281
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachineTemplate" )
332
282
os .Exit (1 )
333
283
}
334
- if err = (& infrav1.AWSCluster {}).SetupWebhookWithManager (mgr ); err != nil {
284
+ if err : = (& infrav1.AWSCluster {}).SetupWebhookWithManager (mgr ); err != nil {
335
285
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSCluster" )
336
286
os .Exit (1 )
337
287
}
338
- if err = (& infrav1.AWSClusterTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
288
+ if err : = (& infrav1.AWSClusterTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
339
289
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterTemplate" )
340
290
os .Exit (1 )
341
291
}
342
- if err = (& infrav1.AWSClusterControllerIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
292
+ if err : = (& infrav1.AWSClusterControllerIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
343
293
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterControllerIdentity" )
344
294
os .Exit (1 )
345
295
}
346
- if err = (& infrav1.AWSClusterRoleIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
296
+ if err : = (& infrav1.AWSClusterRoleIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
347
297
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterRoleIdentity" )
348
298
os .Exit (1 )
349
299
}
350
- if err = (& infrav1.AWSClusterStaticIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
300
+ if err : = (& infrav1.AWSClusterStaticIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
351
301
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterStaticIdentity" )
352
302
os .Exit (1 )
353
303
}
354
- if err = (& infrav1.AWSMachine {}).SetupWebhookWithManager (mgr ); err != nil {
304
+ if err : = (& infrav1.AWSMachine {}).SetupWebhookWithManager (mgr ); err != nil {
355
305
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachine" )
356
306
os .Exit (1 )
357
307
}
308
+ }
358
309
359
- // +kubebuilder:scaffold:builder
310
+ func setupEKSReconcilersAndWebhooks (ctx context.Context , mgr ctrl.Manager , awsServiceEndpoints []scope.ServiceEndpoint ,
311
+ externalResourceGC bool ,
312
+ ) {
313
+ setupLog .Info ("enabling EKS controllers and webhooks" )
360
314
361
- if err := mgr . AddReadyzCheck ( "webhook" , mgr . GetWebhookServer (). StartedChecker ()); err != nil {
362
- setupLog .Error (err , "unable to create ready check" )
315
+ if syncPeriod > maxEKSSyncPeriod {
316
+ setupLog .Error (errMaxSyncPeriodExceeded , "failed to enable EKS" , "max-sync-period" , maxEKSSyncPeriod , "syn-period" , syncPeriod )
363
317
os .Exit (1 )
364
318
}
365
319
366
- if err := mgr .AddHealthzCheck ("webhook" , mgr .GetWebhookServer ().StartedChecker ()); err != nil {
367
- setupLog .Error (err , "unable to create health check" )
320
+ enableIAM := feature .Gates .Enabled (feature .EKSEnableIAM )
321
+ allowAddRoles := feature .Gates .Enabled (feature .EKSAllowAddRoles )
322
+ setupLog .V (2 ).Info ("EKS IAM role creation" , "enabled" , enableIAM )
323
+ setupLog .V (2 ).Info ("EKS IAM additional roles" , "enabled" , allowAddRoles )
324
+ if allowAddRoles && ! enableIAM {
325
+ setupLog .Error (errEKSInvalidFlags , "cannot use EKSAllowAddRoles flag without EKSEnableIAM" )
368
326
os .Exit (1 )
369
327
}
370
328
371
- setupLog .Info ("starting manager" , "version" , version .Get ().String ())
372
- if err := mgr .Start (ctx ); err != nil {
373
- setupLog .Error (err , "problem running manager" )
329
+ setupLog .V (2 ).Info ("enabling EKS control plane controller" )
330
+ if err := (& ekscontrolplanecontrollers.AWSManagedControlPlaneReconciler {
331
+ Client : mgr .GetClient (),
332
+ EnableIAM : enableIAM ,
333
+ AllowAdditionalRoles : allowAddRoles ,
334
+ Endpoints : awsServiceEndpoints ,
335
+ WatchFilterValue : watchFilterValue ,
336
+ ExternalResourceGC : externalResourceGC ,
337
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
338
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedControlPlane" )
339
+ os .Exit (1 )
340
+ }
341
+
342
+ setupLog .V (2 ).Info ("enabling EKS bootstrap controller" )
343
+ if err := (& eksbootstrapcontrollers.EKSConfigReconciler {
344
+ Client : mgr .GetClient (),
345
+ WatchFilterValue : watchFilterValue ,
346
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
347
+ setupLog .Error (err , "unable to create controller" , "controller" , "EKSConfig" )
348
+ os .Exit (1 )
349
+ }
350
+
351
+ if feature .Gates .Enabled (feature .EKSFargate ) {
352
+ setupLog .V (2 ).Info ("enabling EKS fargate profile controller" )
353
+ if err := (& expcontrollers.AWSFargateProfileReconciler {
354
+ Client : mgr .GetClient (),
355
+ Recorder : mgr .GetEventRecorderFor ("awsfargateprofile-reconciler" ),
356
+ EnableIAM : enableIAM ,
357
+ Endpoints : awsServiceEndpoints ,
358
+ WatchFilterValue : watchFilterValue ,
359
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
360
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSFargateProfile" )
361
+ }
362
+
363
+ if err := (& expinfrav1.AWSFargateProfile {}).SetupWebhookWithManager (mgr ); err != nil {
364
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSFargateProfile" )
365
+ os .Exit (1 )
366
+ }
367
+ }
368
+
369
+ if feature .Gates .Enabled (feature .MachinePool ) {
370
+ setupLog .V (2 ).Info ("enabling EKS managed machine pool controller" )
371
+ if err := (& expcontrollers.AWSManagedMachinePoolReconciler {
372
+ AllowAdditionalRoles : allowAddRoles ,
373
+ Client : mgr .GetClient (),
374
+ EnableIAM : enableIAM ,
375
+ Endpoints : awsServiceEndpoints ,
376
+ Recorder : mgr .GetEventRecorderFor ("awsmanagedmachinepool-reconciler" ),
377
+ WatchFilterValue : watchFilterValue ,
378
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
379
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedMachinePool" )
380
+ os .Exit (1 )
381
+ }
382
+
383
+ if err := (& expinfrav1.AWSManagedMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
384
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedMachinePool" )
385
+ os .Exit (1 )
386
+ }
387
+ }
388
+
389
+ if err := (& ekscontrolplanev1.AWSManagedControlPlane {}).SetupWebhookWithManager (mgr ); err != nil {
390
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedControlPlane" )
374
391
os .Exit (1 )
375
392
}
376
393
}
0 commit comments