Skip to content

Commit

Permalink
HFC improvements
Browse files Browse the repository at this point in the history
- Fixed the comments provided in the upstream review
- investigation about how to update the newer firmware information
in Status after the update.
  • Loading branch information
iurygregory committed Jul 26, 2024
1 parent d8000a5 commit dcb99c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
clearHostFirmwareComponentsUpdates(hfc)
}
return recordActionFailure(info, metal3api.PreparationError, provResult.ErrorMessage)
}

Expand Down Expand Up @@ -1287,6 +1291,11 @@ func clearHostProvisioningSettings(host *metal3api.BareMetalHost) {
host.Status.Provisioning.Firmware = nil
}

// clearHostFirmwareComponentsUpdates removes the values related to Updates from status.
func clearHostFirmwareComponentsUpdates(hfc *metal3api.HostFirmwareComponents) {
hfc.Status.Updates = nil
}

func (r *BareMetalHostReconciler) actionDeprovisioning(prov provisioner.Provisioner, info *reconcileInfo) actionResult {
if info.host.Status.Provisioning.Image.URL != "" {
// Adopt the host in case it has been re-registered during the
Expand Down Expand Up @@ -1764,9 +1773,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()
Expand Down Expand Up @@ -1902,8 +1909,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
Expand Down
6 changes: 6 additions & 0 deletions controllers/metal3.io/hostfirmwarecomponents_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (r *HostFirmwareComponentsReconciler) updateHostFirmware(info *rhfcInfo, co
generation := info.hfc.GetGeneration()

newStatus := info.hfc.Status.DeepCopy()

componentInfoMismatch := !reflect.DeepEqual(info.hfc.Status.Components, components)
newStatus.Components = components

if updatesMismatch {
Expand All @@ -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")
Expand Down

0 comments on commit dcb99c2

Please sign in to comment.