From cb164d494e38960998b18d3d083dd1a8ee433b6e Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Mon, 25 Nov 2024 08:56:35 -0700 Subject: [PATCH 1/2] Remove commented out code: Signed-off-by: Jacob Weinstock --- controller/machine/hardware.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/controller/machine/hardware.go b/controller/machine/hardware.go index 5a69b2f..0acf8aa 100644 --- a/controller/machine/hardware.go +++ b/controller/machine/hardware.go @@ -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) From 47ea01ee4f61369b58f0cd03399da664f9ec2369 Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Mon, 25 Nov 2024 11:45:21 -0700 Subject: [PATCH 2/2] 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 --- controller/machine/scope.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/controller/machine/scope.go b/controller/machine/scope.go index 0991176..fdca0e9 100644 --- a/controller/machine/scope.go +++ b/controller/machine/scope.go @@ -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 }