Skip to content

Commit

Permalink
Addressed review comments. Fixed unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Anders <[email protected]>
  • Loading branch information
rhjanders committed Oct 17, 2024
1 parent ab81282 commit 7f4b773
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
21 changes: 8 additions & 13 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,32 +1360,27 @@ func (r *BareMetalHostReconciler) actionDeprovisioning(prov provisioner.Provisio
func (r *BareMetalHostReconciler) checkServicing(prov provisioner.Provisioner, info *reconcileInfo, hup *metal3api.HostUpdatePolicy) (result actionResult, isServicing bool) {
servicingData := provisioner.ServicingData{}

var fwDirty bool
var hfsDirty bool

// (NOTE)janders: since Servicing is an opt-in feature that requires HostUpdatePolicy to be created and set to onReboot
// set below booleans to false by default and change to true based on policy settings

servicingData.LiveFirmwareUpdateAllowed = false
servicingData.LiveFirmwareSettingsAllowed = false
var fwDirty bool
var hfsDirty bool
var LiveFirmwareUpdatesAllowed bool
var LiveFirmwareSettingsAllowed bool

if hup != nil {
if hup.Spec.FirmwareSettings == metal3api.HostUpdatePolicyOnReboot {
servicingData.LiveFirmwareSettingsAllowed = true
}
if hup.Spec.FirmwareUpdates == metal3api.HostUpdatePolicyOnReboot {
servicingData.LiveFirmwareUpdateAllowed = true
}
LiveFirmwareUpdatesAllowed = (hup.Spec.FirmwareUpdates == metal3api.HostUpdatePolicyOnReboot)
LiveFirmwareSettingsAllowed = (hup.Spec.FirmwareSettings == metal3api.HostUpdatePolicyOnReboot)
}

if servicingData.LiveFirmwareUpdateAllowed {
if LiveFirmwareUpdatesAllowed {
if !reflect.DeepEqual(info.host.Status.Provisioning.Firmware, info.host.Spec.Firmware) {
servicingData.FirmwareConfig = info.host.Spec.Firmware
fwDirty = true
}
}

if servicingData.LiveFirmwareSettingsAllowed {
if LiveFirmwareSettingsAllowed {
var hfs *metal3api.HostFirmwareSettings
var err error
hfsDirty, hfs, err = r.getHostFirmwareSettings(info)
Expand Down
18 changes: 17 additions & 1 deletion controllers/metal3.io/baremetalhost_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,23 @@ func TestRebootWithServicing(t *testing.T) {
}
host.Status.Provisioning.Image.URL = "foo"

r := newTestReconciler(host)
// HUP creation
hup := &metal3api.HostUpdatePolicy{
TypeMeta: metav1.TypeMeta{
Kind: "HostUpdatePolicy",
APIVersion: "metal3.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: host.Name,
Namespace: namespace,
},
Spec: metal3api.HostUpdatePolicySpec{
FirmwareSettings: metal3api.HostUpdatePolicyOnReboot,
FirmwareUpdates: metal3api.HostUpdatePolicyOnReboot,
},
}

r := newTestReconciler(host, hup)

tryReconcile(t, r, host,
func(host *metal3api.BareMetalHost, result reconcile.Result) bool {
Expand Down

0 comments on commit 7f4b773

Please sign in to comment.