From a62a16993a8340bb35d8dcbdbbd01513369029da Mon Sep 17 00:00:00 2001 From: Iury Gregory Melo Ferreira Date: Fri, 26 Jul 2024 14:42:50 -0300 Subject: [PATCH] Fix HFC Status This commit fixes the following cases for HFC: - Status Components Information using the newer information that ironic contains. - Clear the Status Updates in case of a failed fiirmware update, so it can retry. Also change the condition as a follow-up to baremetal-operator#1793 Signed-off-by: Iury Gregory Melo Ferreira --- controllers/metal3.io/baremetalhost_controller.go | 12 +++++++----- .../metal3.io/hostfirmwarecomponents_controller.go | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/controllers/metal3.io/baremetalhost_controller.go b/controllers/metal3.io/baremetalhost_controller.go index 2971a680db..40ece1ec62 100644 --- a/controllers/metal3.io/baremetalhost_controller.go +++ b/controllers/metal3.io/baremetalhost_controller.go @@ -1161,6 +1161,10 @@ func (r *BareMetalHostReconciler) actionPreparing(prov provisioner.Provisioner, info.log.Info("handling cleaning error in controller") clearHostProvisioningSettings(info.host) } + if hfcDirty { + info.log.Info("handling cleaning error during firmware update") + hfc.Status.Updates = nil + } return recordActionFailure(info, metal3api.PreparationError, provResult.ErrorMessage) } @@ -1764,9 +1768,7 @@ func (r *BareMetalHostReconciler) saveHostFirmwareComponents(prov provisioner.Pr info.log.Info("saving hostFirmwareComponents information", "spec updates", hfc.Spec.Updates, "status updates", hfc.Status.Updates) hfc.Status.Updates = make([]metal3api.FirmwareUpdate, len(hfc.Spec.Updates)) - for i := range hfc.Spec.Updates { - hfc.Spec.Updates[i].DeepCopyInto(&hfc.Status.Updates[i]) - } + hfc.Status.Updates = hfc.Spec.Updates // Retrieve new information about the firmware components stored in ironic components, err := prov.GetFirmwareComponents() @@ -1902,8 +1904,8 @@ func (r *BareMetalHostReconciler) getHostFirmwareComponents(info *reconcileInfo) return false, nil, nil } - // Check if there are Updates in the Spec that are different than the Status - if meta.IsStatusConditionTrue(hfc.Status.Conditions, string(metal3api.HostFirmwareComponentsChangeDetected)) { + // Check if the condition matches the current Generation to know if the data is not out of date. + if readyCond := meta.FindStatusCondition(hfc.Status.Conditions, string(metal3api.HostFirmwareComponentsChangeDetected)); readyCond != nil && readyCond.Status == metav1.ConditionTrue && readyCond.ObservedGeneration == hfc.Generation { if meta.IsStatusConditionTrue(hfc.Status.Conditions, string(metal3api.HostFirmwareComponentsValid)) { info.log.Info("hostFirmwareComponents indicating ChangeDetected", "namespacename", info.request.NamespacedName) return true, hfc, nil diff --git a/controllers/metal3.io/hostfirmwarecomponents_controller.go b/controllers/metal3.io/hostfirmwarecomponents_controller.go index 6ef4c72fe3..f045e705bd 100644 --- a/controllers/metal3.io/hostfirmwarecomponents_controller.go +++ b/controllers/metal3.io/hostfirmwarecomponents_controller.go @@ -192,6 +192,8 @@ func (r *HostFirmwareComponentsReconciler) updateHostFirmware(info *rhfcInfo, co generation := info.hfc.GetGeneration() newStatus := info.hfc.Status.DeepCopy() + // Check if there is mismatch between ironic information for components and Status. + componentInfoMismatch := !reflect.DeepEqual(info.hfc.Status.Components, components) newStatus.Components = components if updatesMismatch { @@ -218,6 +220,10 @@ func (r *HostFirmwareComponentsReconciler) updateHostFirmware(info *rhfcInfo, co } } + if componentInfoMismatch { + dirty = true + } + // Update Status if has changed if dirty { info.log.Info("Status for HostFirmwareComponents changed")