Skip to content

Commit fb7acbd

Browse files
author
Joshua Reed
committed
Cleanup.
1 parent d181eed commit fb7acbd

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

controllers/cloudstackmachinestatechecker_controller.go

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,47 +70,45 @@ func (r *CloudStackMachineStateCheckerReconciler) Reconcile(ctx context.Context,
7070
}
7171

7272
func (r *CloudStackMachineStateCheckerReconciliationRunner) Reconcile() (ctrl.Result, error) {
73-
if res, err := r.RunReconciliationStages(
73+
return r.RunReconciliationStages(
7474
r.GetParent(r.ReconciliationSubject, r.CSMachine),
7575
r.GetParent(r.CSMachine, r.CAPIMachine),
7676
r.CheckPresent(map[string]client.Object{"CloudStackMachine": r.CSMachine, "Machine": r.CAPIMachine}),
77-
r.GetObjectByName(r.CSMachine.Spec.FailureDomainName, r.FailureDomain),
7877
r.GetObjectByName("placeholder", r.FailureDomain,
7978
func() string { return r.CSMachine.Spec.FailureDomainName }),
8079
r.CheckPresent(map[string]client.Object{"CloudStackFailureDomain": r.FailureDomain}),
8180
r.AsFailureDomainUser(&r.FailureDomain.Spec),
82-
); r.ShouldReturn(res, err) {
83-
return res, err
84-
}
85-
86-
if err := r.CSClient.ResolveVMInstanceDetails(r.CSMachine); err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match found") {
87-
return r.ReturnWrappedError(err, "failed to resolve VM instance details")
88-
}
89-
90-
csRunning := r.CSMachine.Status.InstanceState == "Running"
91-
csTimeInState := r.CSMachine.Status.TimeSinceLastStateChange()
92-
capiRunning := r.CAPIMachine.Status.Phase == "Running"
93-
94-
// capiTimeout indicates that a new VM is running, but it isn't reachable due to a network issue or a misconfiguration.
95-
// When this happens, the machine should be deleted or else the cluster won't ever recover.
96-
capiTimeout := csRunning && !capiRunning && csTimeInState > 5*time.Minute
97-
98-
if csRunning && capiRunning {
99-
r.ReconciliationSubject.Status.Ready = true
100-
} else if !csRunning || capiTimeout {
101-
r.Log.Info("CloudStack instance in bad state",
102-
"name", r.CSMachine.Name,
103-
"instance-id", r.CSMachine.Spec.InstanceID,
104-
"cs-state", r.CSMachine.Status.InstanceState,
105-
"cs-time-in-state", csTimeInState.String(),
106-
"capi-phase", r.CAPIMachine.Status.Phase)
107-
108-
if err := r.K8sClient.Delete(r.RequestCtx, r.CAPIMachine); err != nil {
109-
return r.ReturnWrappedError(err, "failed to delete CAPI machine")
110-
}
111-
}
112-
113-
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
81+
func() (ctrl.Result, error) {
82+
if err := r.CSClient.ResolveVMInstanceDetails(r.CSMachine); err != nil {
83+
if !strings.Contains(strings.ToLower(err.Error()), "no match found") {
84+
return r.ReturnWrappedError(err, "failed to resolve VM instance details")
85+
}
86+
}
87+
88+
// capiTimeout indicates that a new VM is running, but it isn't reachable.
89+
// The cluster may not recover if the machine isn't replaced.
90+
csRunning := r.CSMachine.Status.InstanceState == "Running"
91+
csTimeInState := r.CSMachine.Status.TimeSinceLastStateChange()
92+
capiRunning := r.CAPIMachine.Status.Phase == "Running"
93+
capiTimeout := csRunning && !capiRunning && csTimeInState > 5*time.Minute
94+
95+
if csRunning && capiRunning {
96+
r.ReconciliationSubject.Status.Ready = true
97+
} else if !csRunning || capiTimeout {
98+
r.Log.Info("CloudStack instance in bad state",
99+
"name", r.CSMachine.Name,
100+
"instance-id", r.CSMachine.Spec.InstanceID,
101+
"cs-state", r.CSMachine.Status.InstanceState,
102+
"cs-time-in-state", csTimeInState.String(),
103+
"capi-phase", r.CAPIMachine.Status.Phase)
104+
105+
if err := r.K8sClient.Delete(r.RequestCtx, r.CAPIMachine); err != nil {
106+
return r.ReturnWrappedError(err, "failed to delete CAPI machine")
107+
}
108+
}
109+
110+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
111+
})
114112
}
115113

116114
func (r *CloudStackMachineStateCheckerReconciliationRunner) ReconcileDelete() (ctrl.Result, error) {

0 commit comments

Comments
 (0)