Skip to content

Commit 1d80d2d

Browse files
authored
Merge pull request #4300 from wyike/create-requeue
Requque when awsmachine is pending
2 parents 6eafc5e + 9739c77 commit 1d80d2d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

controllers/awsmachine_controller.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
7176
type AWSMachineReconciler struct {
@@ -533,9 +538,11 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
533538
machineScope.Info("EC2 instance state changed", "state", instance.State, "instance-id", *machineScope.GetInstanceID())
534539
}
535540

541+
shouldRequeue := false
536542
switch instance.State {
537543
case infrav1.InstanceStatePending:
538544
machineScope.SetNotReady()
545+
shouldRequeue = true
539546
conditions.MarkFalse(machineScope.AWSMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotReadyReason, clusterv1.ConditionSeverityWarning, "")
540547
case infrav1.InstanceStateStopping, infrav1.InstanceStateStopped:
541548
machineScope.SetNotReady()
@@ -595,6 +602,10 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
595602
}
596603

597604
machineScope.Debug("done reconciling instance", "instance", instance)
605+
if shouldRequeue {
606+
machineScope.Debug("but find the instance is pending, requeue", "instance", instance.ID)
607+
return ctrl.Result{RequeueAfter: DefaultReconcilerRequeue}, nil
608+
}
598609
return ctrl.Result{}, nil
599610
}
600611

0 commit comments

Comments
 (0)