diff --git a/controllers/metal3.io/baremetalhost_controller.go b/controllers/metal3.io/baremetalhost_controller.go index a1cf3e9c9d..9cbe1f3b32 100644 --- a/controllers/metal3.io/baremetalhost_controller.go +++ b/controllers/metal3.io/baremetalhost_controller.go @@ -546,9 +546,17 @@ func (r *BareMetalHostReconciler) actionProvisioning(prov provisioner.Provisione } // If the provisioner had no work, ensure the image settings match. - if info.host.Status.Provisioning.Image != *(info.host.Spec.Image) { - info.log.Info("updating deployed image in status") - info.host.Status.Provisioning.Image = *(info.host.Spec.Image) + if info.host.Spec.Image != nil { + if info.host.Status.Provisioning.Image != *(info.host.Spec.Image) { + info.log.Info("updating deployed image in status") + info.host.Status.Provisioning.Image = *(info.host.Spec.Image) + } + } + if info.host.Spec.LiveImage != nil { + if info.host.Status.Provisioning.LiveImage != *(info.host.Spec.LiveImage) { + info.log.Info("updating booted liveImage in status") + info.host.Status.Provisioning.LiveImage = *(info.host.Spec.LiveImage) + } } // After provisioning we always requeue to ensure we enter the diff --git a/controllers/metal3.io/host_state_machine.go b/controllers/metal3.io/host_state_machine.go index 1835ca4761..5202bc44a6 100644 --- a/controllers/metal3.io/host_state_machine.go +++ b/controllers/metal3.io/host_state_machine.go @@ -111,6 +111,7 @@ func (hsm *hostStateMachine) updateHostStateFrom(initialState metal3v1alpha1.Pro func (hsm *hostStateMachine) ReconcileState(info *reconcileInfo) actionResult { initialState := hsm.Host.Status.Provisioning.State + info.log.Info("SHDEBUG host/state", hsm.Host.Name, initialState) defer hsm.updateHostStateFrom(initialState, info) if hsm.checkInitiateDelete() { @@ -293,16 +294,25 @@ func (hsm *hostStateMachine) provisioningCancelled() bool { if hsm.Host.HasError() { return true } - if hsm.Host.Spec.Image == nil { + if hsm.Host.Spec.Image == nil && hsm.Host.Spec.LiveImage == nil { return true } - if hsm.Host.Spec.Image.URL == "" { + if hsm.Host.Spec.LiveImage != nil && hsm.Host.Spec.LiveImage.URL == "" { return true } - if hsm.Host.Status.Provisioning.Image.URL == "" { + if hsm.Host.Spec.LiveImage != nil && hsm.Host.Status.Provisioning.LiveImage.URL == "" { return false } - if hsm.Host.Spec.Image.URL != hsm.Host.Status.Provisioning.Image.URL { + if hsm.Host.Spec.LiveImage != nil && hsm.Host.Spec.LiveImage.URL != hsm.Host.Status.Provisioning.LiveImage.URL { + return true + } + if hsm.Host.Spec.Image != nil && hsm.Host.Spec.Image.URL == "" { + return true + } + if hsm.Host.Spec.Image != nil && hsm.Host.Status.Provisioning.Image.URL == "" { + return false + } + if hsm.Host.Spec.Image != nil && hsm.Host.Spec.Image.URL != hsm.Host.Status.Provisioning.Image.URL { return true } return false diff --git a/controllers/metal3.io/host_state_machine_test.go b/controllers/metal3.io/host_state_machine_test.go index 7f717658e7..2bc64cd824 100644 --- a/controllers/metal3.io/host_state_machine_test.go +++ b/controllers/metal3.io/host_state_machine_test.go @@ -61,6 +61,38 @@ func TestProvisioningCancelled(t *testing.T) { Expected: true, }, + { + Scenario: "with liveimage url, unprovisioned", + Host: metal3v1alpha1.BareMetalHost{ + ObjectMeta: metav1.ObjectMeta{ + Name: "myhost", + Namespace: "myns", + }, + Spec: metal3v1alpha1.BareMetalHostSpec{ + LiveImage: &metal3v1alpha1.LiveImage{ + URL: "not-empty", + }, + Online: true, + }, + }, + Expected: false, + }, + + { + Scenario: "with liveimage, unprovisioned", + Host: metal3v1alpha1.BareMetalHost{ + ObjectMeta: metav1.ObjectMeta{ + Name: "myhost", + Namespace: "myns", + }, + Spec: metal3v1alpha1.BareMetalHostSpec{ + LiveImage: &metal3v1alpha1.LiveImage{}, + Online: true, + }, + }, + Expected: true, + }, + { Scenario: "without, unprovisioned", Host: metal3v1alpha1.BareMetalHost{