Skip to content

Commit 163f9f4

Browse files
author
Joshua Reed
committed
Fix machine deletion method.
1 parent b861a47 commit 163f9f4

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

pkg/cloud/instance.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,29 +216,18 @@ func (c *client) GetOrCreateVMInstance(
216216

217217
}
218218

219-
// DestroyVMInstance Destroy a VM instance. Assumes machine has been fetched prior and has an instance ID.
219+
// DestroyVMInstance Destroys a VM instance. Assumes machine has been fetched prior and has an instance ID.
220220
func (c *client) DestroyVMInstance(csMachine *infrav1.CloudStackMachine) error {
221221

222-
if err := c.ResolveVMInstanceDetails(csMachine); err == nil && csMachine.Status.InstanceState != "Running" {
223-
if csMachine.Status.InstanceState == "Stopping" ||
224-
csMachine.Status.InstanceState == "Stopped" {
225-
return errors.New("VM deletion in progress")
226-
} else if csMachine.Status.InstanceState == "Expunging" ||
227-
csMachine.Status.InstanceState == "Expunged" {
228-
// VM is stopped and getting expunged. So the desired state is getting satisfied. Let's move on.
229-
return nil
230-
}
231-
} else if err != nil && strings.Contains(strings.ToLower(err.Error()), "no match found") {
232-
// VM doesn't exist. So the desired state is in effect. Our work is done here.
233-
return nil
234-
}
235-
222+
// Attempt deletion regardless of machine state.
236223
p := c.cs.VirtualMachine.NewDestroyVirtualMachineParams(*csMachine.Spec.InstanceID)
237224
p.SetExpunge(true)
238-
_, err := c.csAsync.VirtualMachine.DestroyVirtualMachine(p)
239-
if err != nil && strings.Contains(err.Error(), "unable to find UUID for id") {
240-
// VM doesn't exist. So the desired state is in effect. Our work is done here.
225+
if _, err := c.csAsync.VirtualMachine.DestroyVirtualMachine(p); err != nil &&
226+
strings.Contains(strings.ToLower(err.Error()), "unable to find uuid for id") {
227+
// VM doesn't exist. Success...
241228
return nil
229+
} else if err != nil {
230+
return err
242231
}
243232
return errors.New("VM deletion in progress")
244233
}

0 commit comments

Comments
 (0)