@@ -278,30 +278,26 @@ func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (retRes ctrl.R
278278 r .ReconciliationSubject .Status .Status = pointer .String (metav1 .StatusFailure )
279279 r .ReconciliationSubject .Status .Reason = pointer .String (err .Error () +
280280 fmt .Sprintf (" If this VM has already been deleted, please remove the finalizer named %s from object %s" ,
281- "cloudstackmachine.infrastructure.cluster.x-k8s.io" , r .ReconciliationSubject .Name ))
281+ "cloudstackmachine.infrastructure.cluster.x-k8s.io" , r .ReconciliationSubject .Name ))
282282 // Cloudstack VM may be not found or more than one found by name
283283 return ctrl.Result {}, err
284284 }
285285 }
286- if r .ReconciliationSubject .Spec .InstanceID != nil {
287- r .Log .Info ("Deleting instance" , "instance-id" , r .ReconciliationSubject .Spec .InstanceID )
288- // Use CSClient instead of CSUser here to expunge as admin.
289- // The CloudStack-Go API does not return an error, but the VM won't delete with Expunge set if requested by
290- // non-domain admin user.
291- if err := r .CSClient .DestroyVMInstance (r .ReconciliationSubject ); err != nil {
292- if err .Error () == "VM deletion in progress" {
293- r .Log .Info (err .Error ())
294- return ctrl.Result {RequeueAfter : utils .DestoryVMRequeueInterval }, nil
295- }
296- return ctrl.Result {}, err
286+ r .Log .Info ("Deleting instance" , "instance-id" , r .ReconciliationSubject .Spec .InstanceID )
287+ // Use CSClient instead of CSUser here to expunge as admin.
288+ // The CloudStack-Go API does not return an error, but the VM won't delete with Expunge set if requested by
289+ // non-domain admin user.
290+ if err := r .CSClient .DestroyVMInstance (r .ReconciliationSubject ); err != nil {
291+ if err .Error () == "VM deletion in progress" {
292+ r .Log .Info (err .Error ())
293+ return ctrl.Result {RequeueAfter : utils .DestoryVMRequeueInterval }, nil
297294 }
298-
299- controllerutil .RemoveFinalizer (r .ReconciliationSubject , infrav1 .MachineFinalizer )
300- r .Log .Info ("VM Deleted" , "instanceID" , r .ReconciliationSubject .Spec .InstanceID )
301- return ctrl.Result {}, nil
295+ return ctrl.Result {}, err
302296 }
303297
304- return ctrl.Result {}, errors .Errorf ("could not destroy VM %s without instanceID" , r .ReconciliationSubject .Name )
298+ controllerutil .RemoveFinalizer (r .ReconciliationSubject , infrav1 .MachineFinalizer )
299+ r .Log .Info ("VM Deleted" , "instanceID" , r .ReconciliationSubject .Spec .InstanceID )
300+ return ctrl.Result {}, nil
305301}
306302
307303// SetupWithManager registers the machine reconciler to the CAPI controller manager.
0 commit comments