Skip to content

Commit 9b58cf6

Browse files
authored
Fix Machine deletion (#709)
- Fix `Machine` deletion - Added check for already gone `Machine`s (transient domain) Fixes #710 Signed-off-by: Lukas Frank <lukas.frank@sap.com>
1 parent b7407b6 commit 9b58cf6

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

internal/controllers/machine_controller.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,23 @@ func (r *MachineReconciler) deleteMachine(ctx context.Context, log logr.Logger,
340340
return r.shutdownMachine(log, machine, domain)
341341
}
342342

343-
return false, r.destroyDomain(log, machine, domain)
343+
return false, r.forceShutdownMachine(log, machine, domain)
344344
}
345345

346-
func (r *MachineReconciler) destroyDomain(log logr.Logger, machine *api.Machine, domain libvirt.Domain) error {
346+
func (r *MachineReconciler) forceShutdownMachine(log logr.Logger, machine *api.Machine, domain libvirt.Domain) error {
347+
state, err := r.getMachineState(machine.ID)
348+
if err != nil {
349+
if libvirt.IsNotFound(err) {
350+
return nil
351+
}
352+
return fmt.Errorf("failed to get machine state: %w", err)
353+
}
354+
355+
if state == api.MachineStateTerminated {
356+
log.V(1).Info("Domain already shut off, skipping destroy")
357+
return nil
358+
}
359+
347360
// DomainDestroyFlags is a blocking operation, and its synchronous nature may pose potential performance issues in the future.
348361
// During test involving 26 empty disks, the function call took a maximum of 1 second to complete.
349362
if err := r.host.Libvirt().DomainDestroyFlags(domain, libvirt.DomainDestroyGraceful); err != nil {

0 commit comments

Comments
 (0)