@@ -226,36 +226,25 @@ func (hsm *hostStateMachine) checkInitiateDelete(log logr.Logger) bool {
226226 return false
227227 }
228228
229+ if hsm .NextState != metal3api .StateDeleting && hsm .Host .OperationalStatus () == metal3api .OperationalStatusDetached {
230+ if delayDeleteForDetachedHost (hsm .Host ) {
231+ log .Info ("delaying detached host deletion" )
232+ deleteDelayedForDetached .Inc ()
233+ return false
234+ }
235+ log .Info ("requested deletion of a detached host, skipping power off and deprovisioning" , "currentState" , hsm .NextState )
236+ hsm .NextState = metal3api .StateDeleting
237+ return true
238+ }
239+
229240 switch hsm .NextState {
230241 default :
231242 hsm .NextState = metal3api .StatePoweringOffBeforeDelete
232243 case metal3api .StateRegistering , metal3api .StateUnmanaged , metal3api .StateNone :
233244 // Skip the power off before delete
234245 hsm .NextState = metal3api .StateDeleting
235246 case metal3api .StateProvisioning , metal3api .StateProvisioned :
236- if hsm .Host .OperationalStatus () == metal3api .OperationalStatusDetached {
237- if delayDeleteForDetachedHost (hsm .Host ) {
238- log .Info ("Delaying detached host deletion" )
239- deleteDelayedForDetached .Inc ()
240- return false
241- }
242- // We cannot power off a detached host. Skip to delete.
243- hsm .NextState = metal3api .StateDeleting
244- } else {
245- hsm .NextState = metal3api .StateDeprovisioning
246- }
247- case metal3api .StateExternallyProvisioned :
248- if hsm .Host .OperationalStatus () == metal3api .OperationalStatusDetached {
249- if delayDeleteForDetachedHost (hsm .Host ) {
250- log .Info ("Delaying detached host deletion" )
251- deleteDelayedForDetached .Inc ()
252- return false
253- }
254- // We cannot power off a detached host. Skip to delete.
255- hsm .NextState = metal3api .StateDeleting
256- } else {
257- hsm .NextState = metal3api .StatePoweringOffBeforeDelete
258- }
247+ hsm .NextState = metal3api .StateDeprovisioning
259248 case metal3api .StateDeprovisioning :
260249 if hsm .Host .Status .ErrorType == metal3api .RegistrationError && hsm .Host .Status .ErrorCount > 3 {
261250 hsm .NextState = metal3api .StateDeleting
0 commit comments