Skip to content

Commit

Permalink
Allow tinkerbellmachine objects to be removed:
Browse files Browse the repository at this point in the history
When a Hardware object corresponding to a tinkerbellmachine
object no longer exists, allow the tinkerbellmachine object
to be removed and clean up associated template and workflow.
At the moment this will skip any BMC operations to power the
machine off and modify the Hardware object. This allows the
tinkerbellmachine to be deleted without needing to know that
it's ok to remove the finalizer and delete the object manually.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Nov 25, 2024
1 parent cb164d4 commit 47ea01e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion controller/machine/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,30 @@ func (scope *machineReconcileScope) DeleteMachineWithDependencies() error {
scope.log.Info("Removing machine", "hardwareName", scope.tinkerbellMachine.Spec.HardwareName)
// Fetch hw for the machine.
hw := &tinkv1.Hardware{}
if err := scope.getHardwareForMachine(hw); err != nil {

err := scope.getHardwareForMachine(hw)
if err != nil && !apierrors.IsNotFound(err) {
return err
}

// If the Hardware is not found, we can't do any BMC operations. In this case we just remove all
// the other dependencies and remove the finalizer from the TinkerbellMachine object so that it can be deleted.
if apierrors.IsNotFound(err) {
scope.log.Info("Hardware not found, only template, workflow and finalizer will be removed",
"hardwareName", scope.tinkerbellMachine.Spec.HardwareName,
)

if err := scope.removeTemplate(); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("removing Template: %w", err)
}

if err := scope.removeWorkflow(); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("removing Workflow: %w", err)
}

return scope.removeFinalizer()
}

if err := scope.removeDependencies(hw); err != nil {
return err
}
Expand Down

0 comments on commit 47ea01e

Please sign in to comment.