Skip to content

Commit

Permalink
allow namespace to continue with terminating when deprovisioning at t…
Browse files Browse the repository at this point in the history
…he same time

print ns to easier tracing

allow namespace to continue with terminating when deprovisioning at the same time
  • Loading branch information
pixelsoccupied committed Feb 23, 2023
1 parent 9d8c582 commit 6bc51c2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,15 @@ func (r *BareMetalHostReconciler) registerHost(prov provisioner.Provisioner, inf
return actionError{err}
}
switch info.host.Status.Provisioning.State {
case metal3v1alpha1.StateRegistering, metal3v1alpha1.StateExternallyProvisioned:
case metal3v1alpha1.StateRegistering, metal3v1alpha1.StateExternallyProvisioned, metal3v1alpha1.StateDeleting:
// No need to create PreprovisioningImage if host is not yet registered
// or is externally provisioned
preprovImgFormats = nil
case metal3v1alpha1.StateDeprovisioning:
// PreprovisioningImage is not required for deprovisioning when cleaning is disabled
if info.host.Spec.AutomatedCleaningMode == metal3v1alpha1.CleaningModeDisabled {
preprovImgFormats = nil
}
}

preprovImg, err := r.getPreprovImage(info, preprovImgFormats)
Expand Down Expand Up @@ -832,9 +837,13 @@ func (r *BareMetalHostReconciler) registerHost(prov provisioner.Provisioner, inf

// Create the hostFirmwareSettings resource with same host name/namespace if it doesn't exist
if info.host.Name != "" {
if err = r.createHostFirmwareSettings(info); err != nil {
info.log.Info("failed creating hostfirmwaresettings")
return actionError{errors.Wrap(err, "failed creating hostFirmwareSettings")}
if !info.host.DeletionTimestamp.IsZero() {
r.Log.Info(fmt.Sprintf("will not attempt to create new hostFirmwareSettings in %s", info.host.Namespace))
} else {
if err = r.createHostFirmwareSettings(info); err != nil {
info.log.Info("failed creating hostfirmwaresettings")
return actionError{errors.Wrap(err, "failed creating hostFirmwareSettings")}
}
}
}

Expand Down Expand Up @@ -971,11 +980,17 @@ func (r *BareMetalHostReconciler) actionInspecting(prov provisioner.Provisioner,
return actionError{errors.Wrap(err, "failed to delete hardwareData")}
}
}

if !info.host.DeletionTimestamp.IsZero() {
info.log.Info(fmt.Sprintf("will not attempt to create hardwareData in %q", hd.Namespace))
return actionComplete{}
}

// either hardwareData was deleted above, or not found. We need to re-create it
if err := r.Client.Create(context.Background(), hd); err != nil {
return actionError{errors.Wrap(err, "failed to create hardwareData")}
}
info.log.Info(fmt.Sprintf("Created hardwareData %q in %q namespace\n", string(hd.Name), string(hd.Namespace)))
info.log.Info(fmt.Sprintf("Created hardwareData %q in %q namespace\n", hd.Name, hd.Namespace))

return actionComplete{}
}
Expand Down

0 comments on commit 6bc51c2

Please sign in to comment.