@@ -70,47 +70,45 @@ func (r *CloudStackMachineStateCheckerReconciler) Reconcile(ctx context.Context,
70
70
}
71
71
72
72
func (r * CloudStackMachineStateCheckerReconciliationRunner ) Reconcile () (ctrl.Result , error ) {
73
- if res , err := r .RunReconciliationStages (
73
+ return r .RunReconciliationStages (
74
74
r .GetParent (r .ReconciliationSubject , r .CSMachine ),
75
75
r .GetParent (r .CSMachine , r .CAPIMachine ),
76
76
r .CheckPresent (map [string ]client.Object {"CloudStackMachine" : r .CSMachine , "Machine" : r .CAPIMachine }),
77
- r .GetObjectByName (r .CSMachine .Spec .FailureDomainName , r .FailureDomain ),
78
77
r .GetObjectByName ("placeholder" , r .FailureDomain ,
79
78
func () string { return r .CSMachine .Spec .FailureDomainName }),
80
79
r .CheckPresent (map [string ]client.Object {"CloudStackFailureDomain" : r .FailureDomain }),
81
80
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
+ })
114
112
}
115
113
116
114
func (r * CloudStackMachineStateCheckerReconciliationRunner ) ReconcileDelete () (ctrl.Result , error ) {
0 commit comments