@@ -619,8 +619,14 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
619619		}
620620
621621		if  err  :=  r .reconcileLBAttachment (machineScope , elbScope , instance ); err  !=  nil  {
622- 			machineScope .Error (err , "failed to reconcile LB attachment" )
623- 			return  ctrl.Result {}, err 
622+ 			// We are tolerating InstanceNotRunning error, so we don't report it as an error condition. 
623+ 			// Because we are reconciling all load balancers, attempt to treat the error as a list of errors. 
624+ 			if  err  :=  kerrors .FilterOut (err , elb .IsInstanceNotRunning ); err  !=  nil  {
625+ 				machineScope .Error (err , "failed to reconcile LB attachment" )
626+ 				return  ctrl.Result {}, err 
627+ 			}
628+ 			// Cannot attach non-running instances to LB 
629+ 			shouldRequeue  =  true 
624630		}
625631	}
626632
@@ -1002,6 +1008,14 @@ func (r *AWSMachineReconciler) registerInstanceToV2LB(machineScope *scope.Machin
10021008		return  nil 
10031009	}
10041010
1011+ 	// See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-register-targets.html#register-instances 
1012+ 	if  ptr .Deref (machineScope .GetInstanceState (), infrav1 .InstanceStatePending ) !=  infrav1 .InstanceStateRunning  {
1013+ 		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
1014+ 			"Cannot register control plane instance %q with load balancer: instance is not running" , instance .ID )
1015+ 		conditions .MarkFalse (machineScope .AWSMachine , infrav1 .ELBAttachedCondition , infrav1 .ELBAttachFailedReason , clusterv1 .ConditionSeverityInfo , "instance not running" )
1016+ 		return  elb .NewInstanceNotRunning ("instance is not running" )
1017+ 	}
1018+ 
10051019	if  err  :=  elbsvc .RegisterInstanceWithAPIServerLB (instance , lb ); err  !=  nil  {
10061020		r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
10071021			"Failed to register control plane instance %q with load balancer: %v" , instance .ID , err )
0 commit comments