From 03de2c325511c35b21580ea5290c9a55fe55bc7c Mon Sep 17 00:00:00 2001 From: Wonkun Kim Date: Mon, 16 May 2022 22:41:40 -0500 Subject: [PATCH] Check VM instance ID is nil when deleting CS machine --- controllers/cloudstackmachine_controller.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controllers/cloudstackmachine_controller.go b/controllers/cloudstackmachine_controller.go index 76d3d8aa..dd01eb3f 100644 --- a/controllers/cloudstackmachine_controller.go +++ b/controllers/cloudstackmachine_controller.go @@ -249,6 +249,10 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateMachineStateChecker() } func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (retRes ctrl.Result, reterr error) { + if r.ReconciliationSubject.Spec.InstanceID == nil { + r.Log.Info("VM Instance ID is nil") + return ctrl.Result{}, nil + } r.Log.Info("Deleting instance", "instance-id", r.ReconciliationSubject.Spec.InstanceID) // Use CSClient instead of CSUser here to expunge as admin. // The CloudStack-Go API does not return an error, but the VM won't delete with Expunge set if requested by @@ -260,7 +264,7 @@ func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (retRes ctrl.R } return ctrl.Result{}, err } - r.Log.Info("VM Deleted.") + r.Log.Info("VM Deleted") controllerutil.RemoveFinalizer(r.ReconciliationSubject, infrav1.MachineFinalizer) return ctrl.Result{}, nil }