From eb4549bc24ffffd31e258a3a6c046c2cb739c1a5 Mon Sep 17 00:00:00 2001 From: Yike Wang Date: Wed, 31 May 2023 09:35:48 +0800 Subject: [PATCH] Requque when awsmachine is pending --- controllers/awsmachine_controller.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/controllers/awsmachine_controller.go b/controllers/awsmachine_controller.go index c903deb3b0..acf5c52113 100644 --- a/controllers/awsmachine_controller.go +++ b/controllers/awsmachine_controller.go @@ -64,8 +64,13 @@ import ( "sigs.k8s.io/cluster-api/util/predicates" ) -// InstanceIDIndex defines the aws machine controller's instance ID index. -const InstanceIDIndex = ".spec.instanceID" +const ( + // InstanceIDIndex defines the aws machine controller's instance ID index. + InstanceIDIndex = ".spec.instanceID" + + // DefaultReconcilerRequeue is the default value for the reconcile retry. + DefaultReconcilerRequeue = 30 * time.Second +) // AWSMachineReconciler reconciles a AwsMachine object. type AWSMachineReconciler struct { @@ -532,9 +537,11 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope * machineScope.Info("EC2 instance state changed", "state", instance.State, "instance-id", *machineScope.GetInstanceID()) } + shouldRequeue := false switch instance.State { case infrav1.InstanceStatePending: machineScope.SetNotReady() + shouldRequeue = true conditions.MarkFalse(machineScope.AWSMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotReadyReason, clusterv1.ConditionSeverityWarning, "") case infrav1.InstanceStateStopping, infrav1.InstanceStateStopped: machineScope.SetNotReady() @@ -594,6 +601,10 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope * } machineScope.Debug("done reconciling instance", "instance", instance) + if shouldRequeue { + machineScope.Debug("but find the instance is pending, requeue", "instance", instance.ID) + return ctrl.Result{RequeueAfter: DefaultReconcilerRequeue}, nil + } return ctrl.Result{}, nil }