Skip to content

Commit

Permalink
Merge pull request #421 from jacobweinstock/orphan-machine
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jacobweinstock authored Nov 25, 2024
2 parents 521dbfe + 47ea01e commit 2c72446
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 0 additions & 12 deletions controller/machine/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,6 @@ func (scope *machineReconcileScope) releaseHardware(hw *tinkv1.Hardware) error {
delete(hw.ObjectMeta.Labels, HardwareOwnerNameLabel)
delete(hw.ObjectMeta.Labels, HardwareOwnerNamespaceLabel)
delete(hw.ObjectMeta.Annotations, HardwareProvisionedAnnotation)
/*
// setting the AllowPXE=true indicates to Smee that this hardware should be allowed
// to netboot. FYI, this is not authoritative.
// Other hardware values can be set to prohibit netbooting of a machine.
// See this Boots function for the logic around this:
// https://github.com/tinkerbell/smee/blob/main/internal/ipxe/script/ipxe.go#L112
for _, ifc := range hw.Spec.Interfaces {
if ifc.Netboot != nil {
ifc.Netboot.AllowPXE = ptr.To(true)
}
}
*/

controllerutil.RemoveFinalizer(hw, infrastructurev1.MachineFinalizer)

Expand Down
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 2c72446

Please sign in to comment.