@@ -224,13 +224,13 @@ func (r *AWSMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
224
224
switch infraScope := infraCluster .(type ) {
225
225
case * scope.ManagedControlPlaneScope :
226
226
if ! awsMachine .ObjectMeta .DeletionTimestamp .IsZero () {
227
- return r .reconcileDelete (machineScope , infraScope , infraScope , nil , nil )
227
+ return r .reconcileDelete (ctx , machineScope , infraScope , infraScope , nil , nil )
228
228
}
229
229
230
230
return r .reconcileNormal (ctx , machineScope , infraScope , infraScope , nil , nil )
231
231
case * scope.ClusterScope :
232
232
if ! awsMachine .ObjectMeta .DeletionTimestamp .IsZero () {
233
- return r .reconcileDelete (machineScope , infraScope , infraScope , infraScope , infraScope )
233
+ return r .reconcileDelete (ctx , machineScope , infraScope , infraScope , infraScope , infraScope )
234
234
}
235
235
236
236
return r .reconcileNormal (ctx , machineScope , infraScope , infraScope , infraScope , infraScope )
@@ -298,12 +298,12 @@ func (r *AWSMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
298
298
)
299
299
}
300
300
301
- func (r * AWSMachineReconciler ) reconcileDelete (machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , ec2Scope scope.EC2Scope , elbScope scope.ELBScope , objectStoreScope scope.S3Scope ) (ctrl.Result , error ) {
301
+ func (r * AWSMachineReconciler ) reconcileDelete (ctx context. Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , ec2Scope scope.EC2Scope , elbScope scope.ELBScope , objectStoreScope scope.S3Scope ) (ctrl.Result , error ) {
302
302
machineScope .Info ("Handling deleted AWSMachine" )
303
303
304
304
ec2Service := r .getEC2Service (ec2Scope )
305
305
306
- if err := r .deleteBootstrapData (machineScope , clusterScope , objectStoreScope ); err != nil {
306
+ if err := r .deleteBootstrapData (ctx , machineScope , clusterScope , objectStoreScope ); err != nil {
307
307
machineScope .Error (err , "unable to delete machine" )
308
308
return ctrl.Result {}, err
309
309
}
@@ -459,15 +459,15 @@ func (r *AWSMachineReconciler) findInstance(machineScope *scope.MachineScope, ec
459
459
return instance , nil
460
460
}
461
461
462
- func (r * AWSMachineReconciler ) reconcileNormal (_ context.Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , ec2Scope scope.EC2Scope , elbScope scope.ELBScope , objectStoreScope scope.S3Scope ) (ctrl.Result , error ) {
462
+ func (r * AWSMachineReconciler ) reconcileNormal (ctx context.Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , ec2Scope scope.EC2Scope , elbScope scope.ELBScope , objectStoreScope scope.S3Scope ) (ctrl.Result , error ) {
463
463
machineScope .Trace ("Reconciling AWSMachine" )
464
464
465
465
// If the AWSMachine is in an error state, return early.
466
466
if machineScope .HasFailed () {
467
467
machineScope .Info ("Error state detected, skipping reconciliation" )
468
468
469
469
// If we are in a failed state, delete the secret regardless of instance state.
470
- if err := r .deleteBootstrapData (machineScope , clusterScope , objectStoreScope ); err != nil {
470
+ if err := r .deleteBootstrapData (ctx , machineScope , clusterScope , objectStoreScope ); err != nil {
471
471
machineScope .Error (err , "unable to reconcile machine" )
472
472
return ctrl.Result {}, err
473
473
}
@@ -524,7 +524,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
524
524
objectStoreSvc = r .getObjectStoreService (objectStoreScope )
525
525
}
526
526
527
- instance , err = r .createInstance (ec2svc , machineScope , clusterScope , objectStoreSvc )
527
+ instance , err = r .createInstance (ctx , ec2svc , machineScope , clusterScope , objectStoreSvc )
528
528
if err != nil {
529
529
machineScope .Error (err , "unable to create instance" )
530
530
conditions .MarkFalse (machineScope .AWSMachine , infrav1 .InstanceReadyCondition , infrav1 .InstanceProvisionFailedReason , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
@@ -599,7 +599,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
599
599
}
600
600
601
601
// reconcile the deletion of the bootstrap data secret now that we have updated instance state
602
- if deleteSecretErr := r .deleteBootstrapData (machineScope , clusterScope , objectStoreScope ); deleteSecretErr != nil {
602
+ if deleteSecretErr := r .deleteBootstrapData (ctx , machineScope , clusterScope , objectStoreScope ); deleteSecretErr != nil {
603
603
r .Log .Error (deleteSecretErr , "unable to delete secrets" )
604
604
return ctrl.Result {}, deleteSecretErr
605
605
}
@@ -709,10 +709,10 @@ func (r *AWSMachineReconciler) deleteEncryptedBootstrapDataSecret(machineScope *
709
709
return nil
710
710
}
711
711
712
- func (r * AWSMachineReconciler ) createInstance (ec2svc services.EC2Interface , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) (* infrav1.Instance , error ) {
712
+ func (r * AWSMachineReconciler ) createInstance (ctx context. Context , ec2svc services.EC2Interface , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) (* infrav1.Instance , error ) {
713
713
machineScope .Info ("Creating EC2 instance" )
714
714
715
- userData , userDataFormat , userDataErr := r .resolveUserData (machineScope , clusterScope , objectStoreSvc )
715
+ userData , userDataFormat , userDataErr := r .resolveUserData (ctx , machineScope , clusterScope , objectStoreSvc )
716
716
if userDataErr != nil {
717
717
return nil , errors .Wrapf (userDataErr , "failed to resolve userdata" )
718
718
}
@@ -725,7 +725,7 @@ func (r *AWSMachineReconciler) createInstance(ec2svc services.EC2Interface, mach
725
725
return instance , nil
726
726
}
727
727
728
- func (r * AWSMachineReconciler ) resolveUserData (machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) ([]byte , string , error ) {
728
+ func (r * AWSMachineReconciler ) resolveUserData (ctx context. Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) ([]byte , string , error ) {
729
729
userData , userDataFormat , err := machineScope .GetRawBootstrapDataWithFormat ()
730
730
if err != nil {
731
731
r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedGetBootstrapData" , err .Error ())
@@ -746,7 +746,7 @@ func (r *AWSMachineReconciler) resolveUserData(machineScope *scope.MachineScope,
746
746
747
747
switch ignitionStorageType {
748
748
case infrav1 .IgnitionStorageTypeOptionClusterObjectStore :
749
- userData , err = r .generateIgnitionWithRemoteStorage (machineScope , objectStoreSvc , userData )
749
+ userData , err = r .generateIgnitionWithRemoteStorage (ctx , machineScope , objectStoreSvc , userData )
750
750
case infrav1 .IgnitionStorageTypeOptionUnencryptedUserData :
751
751
// No further modifications to userdata are needed for plain storage in UnencryptedUserData.
752
752
default :
@@ -793,13 +793,13 @@ func (r *AWSMachineReconciler) cloudInitUserData(machineScope *scope.MachineScop
793
793
794
794
// generateIgnitionWithRemoteStorage uses a remote object storage (S3 bucket) and stores user data in it,
795
795
// then returns the config to instruct ignition on how to pull the user data from the bucket.
796
- func (r * AWSMachineReconciler ) generateIgnitionWithRemoteStorage (scope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface , userData []byte ) ([]byte , error ) {
796
+ func (r * AWSMachineReconciler ) generateIgnitionWithRemoteStorage (ctx context. Context , scope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface , userData []byte ) ([]byte , error ) {
797
797
if objectStoreSvc == nil {
798
798
return nil , errors .New ("using Ignition by default requires a cluster wide object storage configured at `AWSCluster.Spec.Ignition.S3Bucket`. " +
799
799
"You must configure one or instruct Ignition to use EC2 user data instead, by setting `AWSMachine.Spec.Ignition.StorageType` to `UnencryptedUserData`" )
800
800
}
801
801
802
- objectURL , err := objectStoreSvc .Create (scope , userData )
802
+ objectURL , err := objectStoreSvc .Create (ctx , scope , userData )
803
803
if err != nil {
804
804
return nil , errors .Wrap (err , "creating userdata object" )
805
805
}
@@ -875,7 +875,7 @@ func getIgnitionVersion(scope *scope.MachineScope) string {
875
875
return scope .AWSMachine .Spec .Ignition .Version
876
876
}
877
877
878
- func (r * AWSMachineReconciler ) deleteBootstrapData (machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreScope scope.S3Scope ) error {
878
+ func (r * AWSMachineReconciler ) deleteBootstrapData (ctx context. Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreScope scope.S3Scope ) error {
879
879
_ , userDataFormat , err := machineScope .GetRawBootstrapDataWithFormat ()
880
880
if client .IgnoreNotFound (err ) != nil {
881
881
return errors .Wrap (err , "failed to get raw userdata" )
@@ -889,15 +889,15 @@ func (r *AWSMachineReconciler) deleteBootstrapData(machineScope *scope.MachineSc
889
889
890
890
if objectStoreScope != nil {
891
891
// Bootstrap data will be removed from S3 if it is already populated.
892
- if err := r .deleteIgnitionBootstrapDataFromS3 (machineScope , r .getObjectStoreService (objectStoreScope )); err != nil {
892
+ if err := r .deleteIgnitionBootstrapDataFromS3 (ctx , machineScope , r .getObjectStoreService (objectStoreScope )); err != nil {
893
893
return err
894
894
}
895
895
}
896
896
897
897
return nil
898
898
}
899
899
900
- func (r * AWSMachineReconciler ) deleteIgnitionBootstrapDataFromS3 (machineScope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface ) error {
900
+ func (r * AWSMachineReconciler ) deleteIgnitionBootstrapDataFromS3 (ctx context. Context , machineScope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface ) error {
901
901
// Do nothing if the AWSMachine is not in a failed state, and is operational from an EC2 perspective, but does not have a node reference
902
902
if ! machineScope .HasFailed () && machineScope .InstanceIsOperational () && machineScope .Machine .Status .NodeRef == nil && ! machineScope .AWSMachineIsDeleted () {
903
903
return nil
@@ -921,7 +921,7 @@ func (r *AWSMachineReconciler) deleteIgnitionBootstrapDataFromS3(machineScope *s
921
921
return nil
922
922
}
923
923
924
- if err := objectStoreSvc .Delete (machineScope ); err != nil {
924
+ if err := objectStoreSvc .Delete (ctx , machineScope ); err != nil {
925
925
return errors .Wrap (err , "deleting bootstrap data object" )
926
926
}
927
927
0 commit comments