Skip to content

Commit

Permalink
Add LiveImage support to host_state_machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Hardy committed Dec 23, 2020
1 parent 1caec9d commit 98b83c1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
14 changes: 11 additions & 3 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions controllers/metal3.io/host_state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions controllers/metal3.io/host_state_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 98b83c1

Please sign in to comment.