Skip to content

Commit 47ea01e

Browse files
Allow tinkerbellmachine objects to be removed:
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]>
1 parent cb164d4 commit 47ea01e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

controller/machine/scope.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,30 @@ func (scope *machineReconcileScope) DeleteMachineWithDependencies() error {
199199
scope.log.Info("Removing machine", "hardwareName", scope.tinkerbellMachine.Spec.HardwareName)
200200
// Fetch hw for the machine.
201201
hw := &tinkv1.Hardware{}
202-
if err := scope.getHardwareForMachine(hw); err != nil {
202+
203+
err := scope.getHardwareForMachine(hw)
204+
if err != nil && !apierrors.IsNotFound(err) {
203205
return err
204206
}
205207

208+
// If the Hardware is not found, we can't do any BMC operations. In this case we just remove all
209+
// the other dependencies and remove the finalizer from the TinkerbellMachine object so that it can be deleted.
210+
if apierrors.IsNotFound(err) {
211+
scope.log.Info("Hardware not found, only template, workflow and finalizer will be removed",
212+
"hardwareName", scope.tinkerbellMachine.Spec.HardwareName,
213+
)
214+
215+
if err := scope.removeTemplate(); err != nil && !apierrors.IsNotFound(err) {
216+
return fmt.Errorf("removing Template: %w", err)
217+
}
218+
219+
if err := scope.removeWorkflow(); err != nil && !apierrors.IsNotFound(err) {
220+
return fmt.Errorf("removing Workflow: %w", err)
221+
}
222+
223+
return scope.removeFinalizer()
224+
}
225+
206226
if err := scope.removeDependencies(hw); err != nil {
207227
return err
208228
}

0 commit comments

Comments
 (0)