diff --git a/controllers/metal3.io/host_state_machine.go b/controllers/metal3.io/host_state_machine.go index 3a37d2929f..0a92ea2841 100644 --- a/controllers/metal3.io/host_state_machine.go +++ b/controllers/metal3.io/host_state_machine.go @@ -225,6 +225,9 @@ func (hsm *hostStateMachine) checkInitiateDelete(log logr.Logger) bool { switch hsm.NextState { default: hsm.NextState = metal3api.StatePoweringOffBeforeDelete + case metal3api.StateRegistering, metal3api.StateUnmanaged, metal3api.StateNone: + // Skip the power off before delete + hsm.NextState = metal3api.StateDeleting case metal3api.StateProvisioning, metal3api.StateProvisioned: if hsm.Host.OperationalStatus() == metal3api.OperationalStatusDetached { if delayDeleteForDetachedHost(hsm.Host) { @@ -238,12 +241,20 @@ func (hsm *hostStateMachine) checkInitiateDelete(log logr.Logger) bool { hsm.NextState = metal3api.StateDeprovisioning } case metal3api.StateDeprovisioning: + if hsm.Host.Status.ErrorType == metal3api.RegistrationError && hsm.Host.Status.ErrorCount > 3 { + hsm.NextState = metal3api.StateDeleting + return true + } // Allow state machine to run to continue deprovisioning. return false case metal3api.StateDeleting: // Already in deleting state. Allow state machine to run. return false case metal3api.StatePoweringOffBeforeDelete: + if hsm.Host.Status.ErrorType == metal3api.RegistrationError && hsm.Host.Status.ErrorCount > 3 { + hsm.NextState = metal3api.StateDeleting + return true + } // Already in powering off state. Allow state machine to run. return false } @@ -327,7 +338,7 @@ func (hsm *hostStateMachine) ensureRegistered(info *reconcileInfo) (result actio case metal3api.StateMatchProfile: // Backward compatibility, remove eventually return - case metal3api.StateDeleting, metal3api.StatePoweringOffBeforeDelete: + case metal3api.StateDeleting: // In the deleting state the whole idea is to de-register the host return case metal3api.StateRegistering: diff --git a/docs/BaremetalHost_ProvisioningState.dot b/docs/BaremetalHost_ProvisioningState.dot index 4fd8149c5f..5194f89eed 100644 --- a/docs/BaremetalHost_ProvisioningState.dot +++ b/docs/BaremetalHost_ProvisioningState.dot @@ -5,14 +5,14 @@ digraph BaremetalHost { Unmanaged [shape=doublecircle] Unmanaged -> Registering [label="BMC.* != \"\""] - Unmanaged -> PoweringOffBeforeDelete [label="!DeletionTimestamp.IsZero()"] + Unmanaged -> Deleting [label="!DeletionTimestamp.IsZero()"] ExternallyProvisioned [label="Externally\nProvisioned"] Registering -> Inspecting [label="!externallyProvisioned &&\nNeedsHardwareInspection()"] Registering -> Preparing [label="!externallyProvisioned &&\ninspectionDisabled()"] Registering -> ExternallyProvisioned [label="externallyProvisioned"] - Registering -> PoweringOffBeforeDelete [label="!DeletionTimestamp.IsZero()"] + Registering -> Deleting [label="!DeletionTimestamp.IsZero()"] ExternallyProvisioned -> Inspecting [label="!externallyProvisioned &&\nNeedsHardwareInspection()"] ExternallyProvisioned -> Preparing [label="!externallyProvisioned &&\n!NeedsHardwareInspection()"] diff --git a/docs/BaremetalHost_ProvisioningState.png b/docs/BaremetalHost_ProvisioningState.png index 63c3b009fc..086d0766ae 100644 Binary files a/docs/BaremetalHost_ProvisioningState.png and b/docs/BaremetalHost_ProvisioningState.png differ