Skip to content

Commit

Permalink
Don't adopt in deprovisioning if provisioning didn't complete
Browse files Browse the repository at this point in the history
In the deprovisioning state, calling Adopt() on a freshly-reregistered
host will fail if we didn't previously complete provisioning because
there will be no image data stored in the status to pass to the node for
adoption.

Only call Adopt() if the previous provisioning completed and recorded
the requisite image data.

If the node has just been re-registered, it will be in the manageable
state anyway, and thus will still get cleaned before it is next
provisioned.
  • Loading branch information
zaneb committed Jan 15, 2021
1 parent a308ddf commit 24ba8a0
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions controllers/metal3.io/baremetalhost_controller.go
Expand Up @@ -612,26 +612,28 @@ func clearHostProvisioningSettings(host *metal3v1alpha1.BareMetalHost) {
}

func (r *BareMetalHostReconciler) actionDeprovisioning(prov provisioner.Provisioner, info *reconcileInfo) actionResult {
// Adopt the host in case it has been re-registered during the
// deprovisioning process before it completed
provResult, err := prov.Adopt(info.host.Status.ErrorType == metal3v1alpha1.RegistrationError)
if err != nil {
return actionError{err}
}
if provResult.ErrorMessage != "" {
return recordActionFailure(info, metal3v1alpha1.RegistrationError, provResult.ErrorMessage)
}
if provResult.Dirty {
result := actionContinue{provResult.RequeueAfter}
if clearError(info.host) {
return actionUpdate{result}
if info.host.Status.Provisioning.Image.URL != "" {
// Adopt the host in case it has been re-registered during the
// deprovisioning process before it completed
provResult, err := prov.Adopt(info.host.Status.ErrorType == metal3v1alpha1.RegistrationError)
if err != nil {
return actionError{err}
}
if provResult.ErrorMessage != "" {
return recordActionFailure(info, metal3v1alpha1.RegistrationError, provResult.ErrorMessage)
}
if provResult.Dirty {
result := actionContinue{provResult.RequeueAfter}
if clearError(info.host) {
return actionUpdate{result}
}
return result
}
return result
}

info.log.Info("deprovisioning")

provResult, err = prov.Deprovision(info.host.Status.ErrorType == metal3v1alpha1.ProvisioningError)
provResult, err := prov.Deprovision(info.host.Status.ErrorType == metal3v1alpha1.ProvisioningError)
if err != nil {
return actionError{errors.Wrap(err, "failed to deprovision")}
}
Expand Down

0 comments on commit 24ba8a0

Please sign in to comment.