Skip to content

Commit 2c72446

Browse files
Merge pull request #421 from jacobweinstock/orphan-machine
Allow TinkerbellMachine to be removed when no Hardware exists: ## Description <!--- Please describe what this PR is going to change --> 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. This means BMC operations to power the machine off and modify the Hardware object will all be skipped. While the tinkerbellmachine object can be deleted if the finalizer is removed manually this improves the user experience. ## Why is this needed <!--- Link to issue you have raised --> Fixes: #368 ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## How are existing users impacted? What migration steps/scripts do we need? <!--- Fixes a bug, unblocks installation, removes a component of the stack etc --> <!--- Requires a DB migration script, etc. --> ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents 521dbfe + 47ea01e commit 2c72446

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

controller/machine/hardware.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,6 @@ func (scope *machineReconcileScope) releaseHardware(hw *tinkv1.Hardware) error {
279279
delete(hw.ObjectMeta.Labels, HardwareOwnerNameLabel)
280280
delete(hw.ObjectMeta.Labels, HardwareOwnerNamespaceLabel)
281281
delete(hw.ObjectMeta.Annotations, HardwareProvisionedAnnotation)
282-
/*
283-
// setting the AllowPXE=true indicates to Smee that this hardware should be allowed
284-
// to netboot. FYI, this is not authoritative.
285-
// Other hardware values can be set to prohibit netbooting of a machine.
286-
// See this Boots function for the logic around this:
287-
// https://github.com/tinkerbell/smee/blob/main/internal/ipxe/script/ipxe.go#L112
288-
for _, ifc := range hw.Spec.Interfaces {
289-
if ifc.Netboot != nil {
290-
ifc.Netboot.AllowPXE = ptr.To(true)
291-
}
292-
}
293-
*/
294282

295283
controllerutil.RemoveFinalizer(hw, infrastructurev1.MachineFinalizer)
296284

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)