@@ -309,7 +309,7 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
309309 }
310310
311311 instance , err := r .findInstance (machineScope , ec2Service )
312- if err != nil && err != ec2 .ErrInstanceNotFoundByID {
312+ if err != nil && ! errors . Is ( err , ec2 .ErrInstanceNotFoundByID ) {
313313 machineScope .Error (err , "query to find instance failed" )
314314 return ctrl.Result {}, err
315315 }
@@ -651,8 +651,7 @@ func (r *AWSMachineReconciler) reconcileOperationalState(ctx context.Context, ec
651651 }
652652
653653 // check if the remote kubeconfig works and annotate the cluster
654- _ , ok := machineScope .InfraCluster .InfraCluster ().GetAnnotations ()[scope .KubeconfigReadyAnnotation ]
655- if ! ok && machineScope .IsControlPlane () {
654+ if _ , ok := machineScope .InfraCluster .InfraCluster ().GetAnnotations ()[scope .KubeconfigReadyAnnotation ]; ! ok && machineScope .IsControlPlane () {
656655 // if a control plane node is operational check for a kubeconfig and a working control plane node
657656 // and set the annotation so any reconciliation which requires workload api access can complete
658657 remoteClient , err := machineScope .InfraCluster .RemoteClient ()
@@ -669,23 +668,29 @@ func (r *AWSMachineReconciler) reconcileOperationalState(ctx context.Context, ec
669668 for i := range nodes .Items {
670669 if util .IsNodeReady (& nodes .Items [i ]) {
671670 oneReady = true // if one control plane is ready return true
671+ break
672672 }
673673 }
674674
675- if oneReady {
676- awsCluster := & infrav1.AWSCluster {}
677- key := types.NamespacedName {Namespace : machineScope .InfraCluster .Namespace (), Name : machineScope .InfraCluster .Name ()}
678- if err := r .Client .Get (ctx , key , awsCluster ); err != nil {
679- return err
680- }
681- anno := awsCluster .GetAnnotations ()
682- anno [scope .KubeconfigReadyAnnotation ] = "true"
683- awsCluster .SetAnnotations (anno )
684- if err := r .Client .Update (ctx , awsCluster ); err != nil {
685- return err
686- }
687- } else {
675+ if ! oneReady {
688676 r .Log .Info ("waiting for a control plane node to be ready before annotating the cluster, do you need to deploy a CNI?" )
677+
678+ return nil
679+ }
680+
681+ awsCluster := & infrav1.AWSCluster {}
682+ key := types.NamespacedName {
683+ Namespace : machineScope .InfraCluster .Namespace (),
684+ Name : machineScope .InfraCluster .Name (),
685+ }
686+ if err := r .Client .Get (ctx , key , awsCluster ); err != nil {
687+ return fmt .Errorf ("failed to get aws cluster: %w" , err )
688+ }
689+
690+ awsCluster .Annotations [scope .KubeconfigReadyAnnotation ] = "true"
691+
692+ if err := r .Client .Update (ctx , awsCluster ); err != nil {
693+ return fmt .Errorf ("failed to update aws cluster with new annotation: %w" , err )
689694 }
690695 }
691696
@@ -1206,19 +1211,19 @@ func (r *AWSMachineReconciler) ensureStorageTags(ec2svc services.EC2Interface, i
12061211 if err != nil {
12071212 r .Log .Error (err , "Failed to fetch the changed volume tags in EC2 instance" )
12081213 }
1209- prevAnnotations [volumeID ] = newAnnotation
1214+ annotations [volumeID ] = newAnnotation
12101215 } else {
12111216 newAnnotation , err := r .ensureVolumeTags (ec2svc , aws .String (volumeID ), make (map [string ]interface {}), additionalTags )
12121217 if err != nil {
12131218 r .Log .Error (err , "Failed to fetch the changed volume tags in EC2 instance" )
12141219 }
1215- prevAnnotations [volumeID ] = newAnnotation
1220+ annotations [volumeID ] = newAnnotation
12161221 }
12171222 }
12181223
12191224 if ! cmp .Equal (prevAnnotations , annotations , cmpopts .EquateEmpty ()) {
12201225 // We also need to update the annotation if anything changed.
1221- err = r .updateMachineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation , prevAnnotations )
1226+ err = r .updateMachineAnnotationJSON (machine , VolumeTagsLastAppliedAnnotation , annotations )
12221227 if err != nil {
12231228 r .Log .Error (err , "Failed to fetch the changed volume tags in EC2 instance" )
12241229 }
0 commit comments