Skip to content

Commit c8e6011

Browse files
Deleting CAPI Machine when CloudStackMachine VM is in error state during reconcile. (#61)
* Deleting CAPI Machine when CloudStackMachine VM is in error state during reconcile. * Added return code checking to Delete call recently added.
1 parent 40bd0d9 commit c8e6011

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ func (r *CloudStackMachineReconciler) Reconcile(req ctrl.Request) (retRes ctrl.R
137137
}
138138

139139
// Reconcile a VM instance for creates/updates
140-
return r.reconcile(log, csCluster, csMachine, machine)
140+
return r.reconcile(log, ctx, csCluster, csMachine, machine)
141141
}
142142

143143
// Actually reconcile/Create a VM instance.
144144
func (r *CloudStackMachineReconciler) reconcile(
145145
log logr.Logger,
146+
ctx context.Context,
146147
csCluster *infrav1.CloudStackCluster,
147148
csMachine *infrav1.CloudStackMachine,
148149
machine *capiv1.Machine) (ctrl.Result, error) {
@@ -189,6 +190,12 @@ func (r *CloudStackMachineReconciler) reconcile(
189190
if csMachine.Status.InstanceState == "Running" {
190191
log.Info("Machine instance is Running...")
191192
csMachine.Status.Ready = true
193+
} else if csMachine.Status.InstanceState == "Error" {
194+
log.Info("CloudStackMachine VM in error state. Deleting associated Machine.", "csMachine", csMachine)
195+
if err := r.Client.Delete(ctx, machine); err != nil {
196+
return ctrl.Result{}, err
197+
}
198+
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
192199
} else {
193200
log.Info(fmt.Sprintf("Instance not ready, is %s.", csMachine.Status.InstanceState))
194201
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil

0 commit comments

Comments
 (0)