@@ -64,8 +64,13 @@ import (
6464 "sigs.k8s.io/cluster-api/util/predicates"
6565)
6666
67- // InstanceIDIndex defines the aws machine controller's instance ID index.
68- const InstanceIDIndex = ".spec.instanceID"
67+ const (
68+ // InstanceIDIndex defines the aws machine controller's instance ID index.
69+ InstanceIDIndex = ".spec.instanceID"
70+
71+ // DefaultReconcilerRequeue is the default value for the reconcile retry.
72+ DefaultReconcilerRequeue = 30 * time .Second
73+ )
6974
7075// AWSMachineReconciler reconciles a AwsMachine object.
7176type AWSMachineReconciler struct {
@@ -532,9 +537,11 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
532537 machineScope .Info ("EC2 instance state changed" , "state" , instance .State , "instance-id" , * machineScope .GetInstanceID ())
533538 }
534539
540+ shouldRequeue := false
535541 switch instance .State {
536542 case infrav1 .InstanceStatePending :
537543 machineScope .SetNotReady ()
544+ shouldRequeue = true
538545 conditions .MarkFalse (machineScope .AWSMachine , infrav1 .InstanceReadyCondition , infrav1 .InstanceNotReadyReason , clusterv1 .ConditionSeverityWarning , "" )
539546 case infrav1 .InstanceStateStopping , infrav1 .InstanceStateStopped :
540547 machineScope .SetNotReady ()
@@ -594,6 +601,10 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
594601 }
595602
596603 machineScope .Debug ("done reconciling instance" , "instance" , instance )
604+ if shouldRequeue {
605+ machineScope .Debug ("but find the instance is pending, requeue" , "instance" , instance .ID )
606+ return ctrl.Result {RequeueAfter : DefaultReconcilerRequeue }, nil
607+ }
597608 return ctrl.Result {}, nil
598609}
599610
0 commit comments