Skip to content

Commit

Permalink
Check for registration errors before starting provisioning
Browse files Browse the repository at this point in the history
Errors in the Provisioning state are assumed to be provisioning errors,
which the controller will deal with by deprovisioning the Host. To
reduce the incidence of this misclassification, check for registration
errors before allowing the Host to move from the Ready state to
Provisioning. This ensures that any errors seen in the Provisioning
state occurred during provisioning and don't pre-date entry to that
state.

However, since typical usage of the API is to set an image to provision
and toggle the power state on at the same time, do not manage the host
power if the host needs provisioning - we don't wish to power the host
on if it was off only to have to start the provisioning process (which
also needs to manipulate the host power) immediately.
  • Loading branch information
zaneb committed Jan 8, 2020
1 parent bf6254b commit 421a233
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/baremetalhost/baremetalhost_controller.go
Expand Up @@ -683,6 +683,10 @@ func (r *ReconcileBareMetalHost) actionManageReady(prov provisioner.Provisioner,
return actionContinue{provResult.RequeueAfter}
}

if info.host.NeedsProvisioning() {
info.host.ClearError()
return actionComplete{}
}
return r.manageHostPower(prov, info)
}

Expand Down
29 changes: 15 additions & 14 deletions pkg/controller/baremetalhost/host_state_machine.go
Expand Up @@ -237,24 +237,25 @@ func (hsm *hostStateMachine) handleExternallyProvisioned(info *reconcileInfo) ac
}

func (hsm *hostStateMachine) handleReady(info *reconcileInfo) actionResult {
switch {
case hsm.Host.Spec.ExternallyProvisioned:
if hsm.Host.Spec.ExternallyProvisioned {
hsm.NextState = metal3v1alpha1.StateExternallyProvisioned
case hsm.Host.NeedsProvisioning():
return actionComplete{}
}

actResult := hsm.Reconciler.actionManageReady(hsm.Provisioner, info)

switch r := actResult.(type) {
case actionComplete:
hsm.NextState = metal3v1alpha1.StateProvisioning
default:
actResult := hsm.Reconciler.actionManageReady(hsm.Provisioner, info)
if r, f := actResult.(actionFailed); f {
switch r.ErrorType {
case metal3v1alpha1.PowerManagementError:
hsm.NextState = metal3v1alpha1.StatePowerManagementError
case metal3v1alpha1.RegistrationError:
hsm.NextState = metal3v1alpha1.StateRegistrationError
}
case actionFailed:
switch r.ErrorType {
case metal3v1alpha1.PowerManagementError:
hsm.NextState = metal3v1alpha1.StatePowerManagementError
case metal3v1alpha1.RegistrationError:
hsm.NextState = metal3v1alpha1.StateRegistrationError
}
return actResult
}
return actionComplete{}
return actResult
}

func (hsm *hostStateMachine) handleProvisioning(info *reconcileInfo) actionResult {
Expand Down

0 comments on commit 421a233

Please sign in to comment.