@@ -619,8 +619,14 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
619
619
}
620
620
621
621
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
624
630
}
625
631
}
626
632
@@ -1002,6 +1008,14 @@ func (r *AWSMachineReconciler) registerInstanceToV2LB(machineScope *scope.Machin
1002
1008
return nil
1003
1009
}
1004
1010
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
+
1005
1019
if err := elbsvc .RegisterInstanceWithAPIServerLB (instance , lb ); err != nil {
1006
1020
r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "FailedAttachControlPlaneELB" ,
1007
1021
"Failed to register control plane instance %q with load balancer: %v" , instance .ID , err )
0 commit comments