@@ -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
}
@@ -460,15 +460,15 @@ func (r *AWSMachineReconciler) findInstance(machineScope *scope.MachineScope, ec
460
460
}
461
461
462
462
//nolint:gocyclo
463
- func (r * AWSMachineReconciler ) reconcileNormal (_ context.Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , ec2Scope scope.EC2Scope , elbScope scope.ELBScope , objectStoreScope scope.S3Scope ) (ctrl.Result , error ) {
463
+ 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 ) {
464
464
machineScope .Trace ("Reconciling AWSMachine" )
465
465
466
466
// If the AWSMachine is in an error state, return early.
467
467
if machineScope .HasFailed () {
468
468
machineScope .Info ("Error state detected, skipping reconciliation" )
469
469
470
470
// If we are in a failed state, delete the secret regardless of instance state.
471
- if err := r .deleteBootstrapData (machineScope , clusterScope , objectStoreScope ); err != nil {
471
+ if err := r .deleteBootstrapData (ctx , machineScope , clusterScope , objectStoreScope ); err != nil {
472
472
machineScope .Error (err , "unable to reconcile machine" )
473
473
return ctrl.Result {}, err
474
474
}
@@ -531,7 +531,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
531
531
objectStoreSvc = r .getObjectStoreService (objectStoreScope )
532
532
}
533
533
534
- instance , err = r .createInstance (ec2svc , machineScope , clusterScope , objectStoreSvc )
534
+ instance , err = r .createInstance (ctx , ec2svc , machineScope , clusterScope , objectStoreSvc )
535
535
if err != nil {
536
536
machineScope .Error (err , "unable to create instance" )
537
537
conditions .MarkFalse (machineScope .AWSMachine , infrav1 .InstanceReadyCondition , infrav1 .InstanceProvisionFailedReason , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
@@ -616,7 +616,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
616
616
617
617
// reconcile the deletion of the bootstrap data secret now that we have updated instance state
618
618
if ! machineScope .IsMachinePoolMachine () {
619
- if deleteSecretErr := r .deleteBootstrapData (machineScope , clusterScope , objectStoreScope ); deleteSecretErr != nil {
619
+ if deleteSecretErr := r .deleteBootstrapData (ctx , machineScope , clusterScope , objectStoreScope ); deleteSecretErr != nil {
620
620
r .Log .Error (deleteSecretErr , "unable to delete secrets" )
621
621
return ctrl.Result {}, deleteSecretErr
622
622
}
@@ -729,10 +729,10 @@ func (r *AWSMachineReconciler) deleteEncryptedBootstrapDataSecret(machineScope *
729
729
return nil
730
730
}
731
731
732
- func (r * AWSMachineReconciler ) createInstance (ec2svc services.EC2Interface , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) (* infrav1.Instance , error ) {
732
+ func (r * AWSMachineReconciler ) createInstance (ctx context. Context , ec2svc services.EC2Interface , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) (* infrav1.Instance , error ) {
733
733
machineScope .Info ("Creating EC2 instance" )
734
734
735
- userData , userDataFormat , userDataErr := r .resolveUserData (machineScope , clusterScope , objectStoreSvc )
735
+ userData , userDataFormat , userDataErr := r .resolveUserData (ctx , machineScope , clusterScope , objectStoreSvc )
736
736
if userDataErr != nil {
737
737
return nil , errors .Wrapf (userDataErr , "failed to resolve userdata" )
738
738
}
@@ -745,7 +745,7 @@ func (r *AWSMachineReconciler) createInstance(ec2svc services.EC2Interface, mach
745
745
return instance , nil
746
746
}
747
747
748
- func (r * AWSMachineReconciler ) resolveUserData (machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) ([]byte , string , error ) {
748
+ func (r * AWSMachineReconciler ) resolveUserData (ctx context. Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreSvc services.ObjectStoreInterface ) ([]byte , string , error ) {
749
749
userData , userDataFormat , err := machineScope .GetRawBootstrapDataWithFormat ()
750
750
if err != nil {
751
751
r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedGetBootstrapData" , err .Error ())
@@ -766,7 +766,7 @@ func (r *AWSMachineReconciler) resolveUserData(machineScope *scope.MachineScope,
766
766
767
767
switch ignitionStorageType {
768
768
case infrav1 .IgnitionStorageTypeOptionClusterObjectStore :
769
- userData , err = r .generateIgnitionWithRemoteStorage (machineScope , objectStoreSvc , userData )
769
+ userData , err = r .generateIgnitionWithRemoteStorage (ctx , machineScope , objectStoreSvc , userData )
770
770
case infrav1 .IgnitionStorageTypeOptionUnencryptedUserData :
771
771
// No further modifications to userdata are needed for plain storage in UnencryptedUserData.
772
772
default :
@@ -813,13 +813,13 @@ func (r *AWSMachineReconciler) cloudInitUserData(machineScope *scope.MachineScop
813
813
814
814
// generateIgnitionWithRemoteStorage uses a remote object storage (S3 bucket) and stores user data in it,
815
815
// then returns the config to instruct ignition on how to pull the user data from the bucket.
816
- func (r * AWSMachineReconciler ) generateIgnitionWithRemoteStorage (scope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface , userData []byte ) ([]byte , error ) {
816
+ func (r * AWSMachineReconciler ) generateIgnitionWithRemoteStorage (ctx context. Context , scope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface , userData []byte ) ([]byte , error ) {
817
817
if objectStoreSvc == nil {
818
818
return nil , errors .New ("using Ignition by default requires a cluster wide object storage configured at `AWSCluster.Spec.Ignition.S3Bucket`. " +
819
819
"You must configure one or instruct Ignition to use EC2 user data instead, by setting `AWSMachine.Spec.Ignition.StorageType` to `UnencryptedUserData`" )
820
820
}
821
821
822
- objectURL , err := objectStoreSvc .Create (scope , userData )
822
+ objectURL , err := objectStoreSvc .Create (ctx , scope , userData )
823
823
if err != nil {
824
824
return nil , errors .Wrap (err , "creating userdata object" )
825
825
}
@@ -895,7 +895,7 @@ func getIgnitionVersion(scope *scope.MachineScope) string {
895
895
return scope .AWSMachine .Spec .Ignition .Version
896
896
}
897
897
898
- func (r * AWSMachineReconciler ) deleteBootstrapData (machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreScope scope.S3Scope ) error {
898
+ func (r * AWSMachineReconciler ) deleteBootstrapData (ctx context. Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , objectStoreScope scope.S3Scope ) error {
899
899
var userDataFormat string
900
900
var err error
901
901
if machineScope .Machine .Spec .Bootstrap .DataSecretName != nil {
@@ -913,15 +913,15 @@ func (r *AWSMachineReconciler) deleteBootstrapData(machineScope *scope.MachineSc
913
913
914
914
if objectStoreScope != nil {
915
915
// Bootstrap data will be removed from S3 if it is already populated.
916
- if err := r .deleteIgnitionBootstrapDataFromS3 (machineScope , r .getObjectStoreService (objectStoreScope )); err != nil {
916
+ if err := r .deleteIgnitionBootstrapDataFromS3 (ctx , machineScope , r .getObjectStoreService (objectStoreScope )); err != nil {
917
917
return err
918
918
}
919
919
}
920
920
921
921
return nil
922
922
}
923
923
924
- func (r * AWSMachineReconciler ) deleteIgnitionBootstrapDataFromS3 (machineScope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface ) error {
924
+ func (r * AWSMachineReconciler ) deleteIgnitionBootstrapDataFromS3 (ctx context. Context , machineScope * scope.MachineScope , objectStoreSvc services.ObjectStoreInterface ) error {
925
925
// 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
926
926
if ! machineScope .HasFailed () && machineScope .InstanceIsOperational () && machineScope .Machine .Status .NodeRef == nil && ! machineScope .AWSMachineIsDeleted () {
927
927
return nil
@@ -945,7 +945,7 @@ func (r *AWSMachineReconciler) deleteIgnitionBootstrapDataFromS3(machineScope *s
945
945
return nil
946
946
}
947
947
948
- if err := objectStoreSvc .Delete (machineScope ); err != nil {
948
+ if err := objectStoreSvc .Delete (ctx , machineScope ); err != nil {
949
949
return errors .Wrap (err , "deleting bootstrap data object" )
950
950
}
951
951
0 commit comments