Skip to content

Commit

Permalink
Merge pull request #4303 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…4300-to-release-2.1

[release-2.1] Requque when awsmachine is pending
  • Loading branch information
k8s-ci-robot authored Jun 1, 2023
2 parents 3b07bae + eb4549b commit 7f7af3e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions controllers/awsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 7f7af3e

Please sign in to comment.