@@ -174,217 +174,224 @@ func main() {
174
174
externalResourceGC = true
175
175
}
176
176
177
+ if feature .Gates .Enabled (feature .BootstrapFormatIgnition ) {
178
+ setupLog .Info ("Enabling Ignition support for machine bootstrap data" )
179
+ }
180
+
177
181
// Parse service endpoints.
178
- AWSServiceEndpoints , err := endpoints .ParseFlag (serviceEndpoints )
182
+ awsServiceEndpoints , err := endpoints .ParseFlag (serviceEndpoints )
179
183
if err != nil {
180
184
setupLog .Error (err , "unable to parse service endpoints" , "controller" , "AWSCluster" )
181
185
os .Exit (1 )
182
186
}
183
187
184
- 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 {
185
216
Client : mgr .GetClient (),
186
217
Log : ctrl .Log .WithName ("controllers" ).WithName ("AWSMachine" ),
187
218
Recorder : mgr .GetEventRecorderFor ("awsmachine-controller" ),
188
- Endpoints : AWSServiceEndpoints ,
219
+ Endpoints : awsServiceEndpoints ,
189
220
WatchFilterValue : watchFilterValue ,
190
221
}).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsMachineConcurrency , RecoverPanic : true }); err != nil {
191
222
setupLog .Error (err , "unable to create controller" , "controller" , "AWSMachine" )
192
223
os .Exit (1 )
193
224
}
194
- if err = (& controllers.AWSClusterReconciler {
225
+
226
+ if err := (& controllers.AWSClusterReconciler {
195
227
Client : mgr .GetClient (),
196
228
Recorder : mgr .GetEventRecorderFor ("awscluster-controller" ),
197
- Endpoints : AWSServiceEndpoints ,
229
+ Endpoints : awsServiceEndpoints ,
198
230
WatchFilterValue : watchFilterValue ,
199
231
ExternalResourceGC : externalResourceGC ,
200
232
}).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
201
233
setupLog .Error (err , "unable to create controller" , "controller" , "AWSCluster" )
202
234
os .Exit (1 )
203
235
}
204
- enableGates (ctx , mgr , AWSServiceEndpoints , externalResourceGC )
205
236
206
- if err = (& infrav1.AWSMachineTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
237
+ if feature .Gates .Enabled (feature .MachinePool ) {
238
+ setupLog .V (2 ).Info ("enabling machine pool controller and webhook" )
239
+ if err := (& expcontrollers.AWSMachinePoolReconciler {
240
+ Client : mgr .GetClient (),
241
+ Recorder : mgr .GetEventRecorderFor ("awsmachinepool-controller" ),
242
+ WatchFilterValue : watchFilterValue ,
243
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
244
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSMachinePool" )
245
+ os .Exit (1 )
246
+ }
247
+
248
+ if err := (& expinfrav1.AWSMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
249
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachinePool" )
250
+ os .Exit (1 )
251
+ }
252
+ }
253
+
254
+ if feature .Gates .Enabled (feature .EventBridgeInstanceState ) {
255
+ setupLog .Info ("EventBridge notifications enabled. enabling AWSInstanceStateController" )
256
+ if err := (& instancestate.AwsInstanceStateReconciler {
257
+ Client : mgr .GetClient (),
258
+ Log : ctrl .Log .WithName ("controllers" ).WithName ("AWSInstanceStateController" ),
259
+ Endpoints : awsServiceEndpoints ,
260
+ WatchFilterValue : watchFilterValue ,
261
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
262
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSInstanceStateController" )
263
+ os .Exit (1 )
264
+ }
265
+ }
266
+
267
+ if feature .Gates .Enabled (feature .AutoControllerIdentityCreator ) {
268
+ setupLog .Info ("AutoControllerIdentityCreator enabled" )
269
+ if err := (& controlleridentitycreator.AWSControllerIdentityReconciler {
270
+ Client : mgr .GetClient (),
271
+ Log : ctrl .Log .WithName ("controllers" ).WithName ("AWSControllerIdentity" ),
272
+ Endpoints : awsServiceEndpoints ,
273
+ WatchFilterValue : watchFilterValue ,
274
+ }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
275
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSControllerIdentity" )
276
+ os .Exit (1 )
277
+ }
278
+ }
279
+
280
+ if err := (& infrav1.AWSMachineTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
207
281
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachineTemplate" )
208
282
os .Exit (1 )
209
283
}
210
- if err = (& infrav1.AWSCluster {}).SetupWebhookWithManager (mgr ); err != nil {
284
+ if err : = (& infrav1.AWSCluster {}).SetupWebhookWithManager (mgr ); err != nil {
211
285
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSCluster" )
212
286
os .Exit (1 )
213
287
}
214
- if err = (& infrav1.AWSClusterTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
288
+ if err : = (& infrav1.AWSClusterTemplate {}).SetupWebhookWithManager (mgr ); err != nil {
215
289
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterTemplate" )
216
290
os .Exit (1 )
217
291
}
218
- if err = (& infrav1.AWSClusterControllerIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
292
+ if err : = (& infrav1.AWSClusterControllerIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
219
293
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterControllerIdentity" )
220
294
os .Exit (1 )
221
295
}
222
- if err = (& infrav1.AWSClusterRoleIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
296
+ if err : = (& infrav1.AWSClusterRoleIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
223
297
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterRoleIdentity" )
224
298
os .Exit (1 )
225
299
}
226
- if err = (& infrav1.AWSClusterStaticIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
300
+ if err : = (& infrav1.AWSClusterStaticIdentity {}).SetupWebhookWithManager (mgr ); err != nil {
227
301
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSClusterStaticIdentity" )
228
302
os .Exit (1 )
229
303
}
230
- if err = (& infrav1.AWSMachine {}).SetupWebhookWithManager (mgr ); err != nil {
304
+ if err : = (& infrav1.AWSMachine {}).SetupWebhookWithManager (mgr ); err != nil {
231
305
setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachine" )
232
306
os .Exit (1 )
233
307
}
234
- if feature .Gates .Enabled (feature .EKS ) {
235
- setupLog .Info ("enabling EKS webhooks" )
236
- if err := (& ekscontrolplanev1.AWSManagedControlPlane {}).SetupWebhookWithManager (mgr ); err != nil {
237
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedControlPlane" )
238
- os .Exit (1 )
239
- }
240
- if feature .Gates .Enabled (feature .EKSFargate ) {
241
- if err = (& expinfrav1.AWSFargateProfile {}).SetupWebhookWithManager (mgr ); err != nil {
242
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSFargateProfile" )
243
- os .Exit (1 )
244
- }
245
- }
246
- if feature .Gates .Enabled (feature .MachinePool ) {
247
- if err = (& expinfrav1.AWSManagedMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
248
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedMachinePool" )
249
- os .Exit (1 )
250
- }
251
- }
252
- }
253
- if feature .Gates .Enabled (feature .MachinePool ) {
254
- setupLog .Info ("enabling webhook for AWSMachinePool" )
255
- if err = (& expinfrav1.AWSMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
256
- setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSMachinePool" )
257
- os .Exit (1 )
258
- }
259
- }
308
+ }
260
309
261
- // +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" )
262
314
263
- if err := mgr . AddReadyzCheck ( "webhook" , mgr . GetWebhookServer (). StartedChecker ()); err != nil {
264
- 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 )
265
317
os .Exit (1 )
266
318
}
267
319
268
- if err := mgr .AddHealthzCheck ("webhook" , mgr .GetWebhookServer ().StartedChecker ()); err != nil {
269
- 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" )
270
326
os .Exit (1 )
271
327
}
272
328
273
- setupLog .Info ("starting manager" , "version" , version .Get ().String ())
274
- if err := mgr .Start (ctx ); err != nil {
275
- 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" )
276
339
os .Exit (1 )
277
340
}
278
- }
279
341
280
- func enableGates (ctx context.Context , mgr ctrl.Manager , awsServiceEndpoints []scope.ServiceEndpoint , externalResourceGC bool ) {
281
- if feature .Gates .Enabled (feature .EKS ) {
282
- setupLog .Info ("enabling EKS controllers" )
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
+ }
283
350
284
- if syncPeriod > maxEKSSyncPeriod {
285
- setupLog .Error (errMaxSyncPeriodExceeded , "failed to enable EKS" , "max-sync-period" , maxEKSSyncPeriod , "syn-period" , syncPeriod )
286
- os .Exit (1 )
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" )
287
361
}
288
362
289
- enableIAM := feature .Gates .Enabled (feature .EKSEnableIAM )
290
- allowAddRoles := feature .Gates .Enabled (feature .EKSAllowAddRoles )
291
- setupLog .V (2 ).Info ("EKS IAM role creation" , "enabled" , enableIAM )
292
- setupLog .V (2 ).Info ("EKS IAM additional roles" , "enabled" , allowAddRoles )
293
- if allowAddRoles && ! enableIAM {
294
- setupLog .Error (errEKSInvalidFlags , "cannot use EKSAllowAddRoles flag without EKSEnableIAM" )
363
+ if err := (& expinfrav1.AWSFargateProfile {}).SetupWebhookWithManager (mgr ); err != nil {
364
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSFargateProfile" )
295
365
os .Exit (1 )
296
366
}
367
+ }
297
368
298
- setupLog .V (2 ).Info ("enabling EKS control plane controller" )
299
- if err := (& ekscontrolplanecontrollers.AWSManagedControlPlaneReconciler {
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 ,
300
373
Client : mgr .GetClient (),
301
374
EnableIAM : enableIAM ,
302
- AllowAdditionalRoles : allowAddRoles ,
303
375
Endpoints : awsServiceEndpoints ,
376
+ Recorder : mgr .GetEventRecorderFor ("awsmanagedmachinepool-reconciler" ),
304
377
WatchFilterValue : watchFilterValue ,
305
- ExternalResourceGC : externalResourceGC ,
306
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
307
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedControlPlane" )
308
- os .Exit (1 )
309
- }
310
-
311
- setupLog .V (2 ).Info ("enabling EKS bootstrap controller" )
312
- if err := (& eksbootstrapcontrollers.EKSConfigReconciler {
313
- Client : mgr .GetClient (),
314
- WatchFilterValue : watchFilterValue ,
315
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
316
- setupLog .Error (err , "unable to create controller" , "controller" , "EKSConfig" )
317
- os .Exit (1 )
318
- }
319
-
320
- if feature .Gates .Enabled (feature .EKSFargate ) {
321
- setupLog .V (2 ).Info ("enabling EKS fargate profile controller" )
322
- if err := (& expcontrollers.AWSFargateProfileReconciler {
323
- Client : mgr .GetClient (),
324
- Recorder : mgr .GetEventRecorderFor ("awsfargateprofile-reconciler" ),
325
- EnableIAM : enableIAM ,
326
- Endpoints : awsServiceEndpoints ,
327
- WatchFilterValue : watchFilterValue ,
328
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
329
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSFargateProfile" )
330
- }
331
- }
332
-
333
- if feature .Gates .Enabled (feature .MachinePool ) {
334
- setupLog .V (2 ).Info ("enabling EKS managed machine pool controller" )
335
- if err := (& expcontrollers.AWSManagedMachinePoolReconciler {
336
- AllowAdditionalRoles : allowAddRoles ,
337
- Client : mgr .GetClient (),
338
- EnableIAM : enableIAM ,
339
- Endpoints : awsServiceEndpoints ,
340
- Recorder : mgr .GetEventRecorderFor ("awsmanagedmachinepool-reconciler" ),
341
- WatchFilterValue : watchFilterValue ,
342
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
343
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedMachinePool" )
344
- os .Exit (1 )
345
- }
346
- }
347
- }
348
- if feature .Gates .Enabled (feature .MachinePool ) {
349
- setupLog .V (2 ).Info ("enabling machine pool controller" )
350
- if err := (& expcontrollers.AWSMachinePoolReconciler {
351
- Client : mgr .GetClient (),
352
- Recorder : mgr .GetEventRecorderFor ("awsmachinepool-controller" ),
353
- WatchFilterValue : watchFilterValue ,
354
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
355
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSMachinePool" )
356
- os .Exit (1 )
357
- }
358
- }
359
- if feature .Gates .Enabled (feature .EventBridgeInstanceState ) {
360
- setupLog .Info ("EventBridge notifications enabled. enabling AWSInstanceStateController" )
361
- if err := (& instancestate.AwsInstanceStateReconciler {
362
- Client : mgr .GetClient (),
363
- Log : ctrl .Log .WithName ("controllers" ).WithName ("AWSInstanceStateController" ),
364
- Endpoints : awsServiceEndpoints ,
365
- WatchFilterValue : watchFilterValue ,
366
378
}).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : instanceStateConcurrency , RecoverPanic : true }); err != nil {
367
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSInstanceStateController " )
379
+ setupLog .Error (err , "unable to create controller" , "controller" , "AWSManagedMachinePool " )
368
380
os .Exit (1 )
369
381
}
370
- }
371
- if feature .Gates .Enabled (feature .AutoControllerIdentityCreator ) {
372
- setupLog .Info ("AutoControllerIdentityCreator enabled" )
373
- if err := (& controlleridentitycreator.AWSControllerIdentityReconciler {
374
- Client : mgr .GetClient (),
375
- Log : ctrl .Log .WithName ("controllers" ).WithName ("AWSControllerIdentity" ),
376
- Endpoints : awsServiceEndpoints ,
377
- WatchFilterValue : watchFilterValue ,
378
- }).SetupWithManager (ctx , mgr , controller.Options {MaxConcurrentReconciles : awsClusterConcurrency , RecoverPanic : true }); err != nil {
379
- setupLog .Error (err , "unable to create controller" , "controller" , "AWSControllerIdentity" )
382
+
383
+ if err := (& expinfrav1.AWSManagedMachinePool {}).SetupWebhookWithManager (mgr ); err != nil {
384
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedMachinePool" )
380
385
os .Exit (1 )
381
386
}
382
387
}
383
388
384
- if feature .Gates .Enabled (feature .BootstrapFormatIgnition ) {
385
- setupLog .Info ("Enabling Ignition support for machine bootstrap data" )
389
+ if err := (& ekscontrolplanev1.AWSManagedControlPlane {}).SetupWebhookWithManager (mgr ); err != nil {
390
+ setupLog .Error (err , "unable to create webhook" , "webhook" , "AWSManagedControlPlane" )
391
+ os .Exit (1 )
386
392
}
387
393
}
394
+
388
395
func initFlags (fs * pflag.FlagSet ) {
389
396
fs .StringVar (
390
397
& metricsBindAddr ,
0 commit comments