Skip to content

Commit ce1fd35

Browse files
committed
Fix a bug where RemoveFinalizer is not called when instance ID is nil
1 parent 155613b commit ce1fd35

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,18 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateMachineStateChecker()
249249
}
250250

251251
func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (retRes ctrl.Result, reterr error) {
252-
if r.ReconciliationSubject.Spec.InstanceID == nil {
253-
r.Log.Info("VM Instance ID is nil")
254-
return ctrl.Result{}, nil
255-
}
256-
r.Log.Info("Deleting instance", "instance-id", r.ReconciliationSubject.Spec.InstanceID)
257-
// Use CSClient instead of CSUser here to expunge as admin.
258-
// The CloudStack-Go API does not return an error, but the VM won't delete with Expunge set if requested by
259-
// non-domain admin user.
260-
if err := r.CSClient.DestroyVMInstance(r.ReconciliationSubject); err != nil {
261-
if err.Error() == "VM deletion in progress" {
262-
r.Log.Info(err.Error())
263-
return ctrl.Result{RequeueAfter: utils.DestoryVMRequeueInterval}, nil
252+
if r.ReconciliationSubject.Spec.InstanceID != nil {
253+
r.Log.Info("Deleting instance", "instance-id", r.ReconciliationSubject.Spec.InstanceID)
254+
// Use CSClient instead of CSUser here to expunge as admin.
255+
// The CloudStack-Go API does not return an error, but the VM won't delete with Expunge set if requested by
256+
// non-domain admin user.
257+
if err := r.CSClient.DestroyVMInstance(r.ReconciliationSubject); err != nil {
258+
if err.Error() == "VM deletion in progress" {
259+
r.Log.Info(err.Error())
260+
return ctrl.Result{RequeueAfter: utils.DestoryVMRequeueInterval}, nil
261+
}
262+
return ctrl.Result{}, err
264263
}
265-
return ctrl.Result{}, err
266264
}
267265
r.Log.Info("VM Deleted")
268266
controllerutil.RemoveFinalizer(r.ReconciliationSubject, infrav1.MachineFinalizer)

0 commit comments

Comments
 (0)