Skip to content

Commit

Permalink
🌱Add condition indicating deletion timestamp is set
Browse files Browse the repository at this point in the history
🌱Fix lint errors

🌱Fix gofmt lint error

🐛Fix condition

🌱Remove Deletion condition

🐛Fix condition errors

🌱Remove condition and split if statements

🐛Fix lint error and remove needsUpdate

🌱Remove if statement
  • Loading branch information
yrs147 committed May 20, 2024
1 parent 2867853 commit d117e35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/conditions_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ const (
HostAssociateFailedReason = "HostAssociateFailed"
)

const (
// DeletionInProgressReason indicates that a host is being deleted.
DeletionInProgressReason = "DeletionInProgress"
)

// deprecated conditions.

const (
Expand Down
26 changes: 16 additions & 10 deletions controllers/hetznerbaremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,25 @@ func (r *HetznerBareMetalHostReconciler) reconcileSelectedStates(ctx context.Con
switch bmHost.Spec.Status.ProvisioningState {
// Handle StateNone: check whether needs to be provisioned or deleted.
case infrav1.StateNone:
var needsUpdate bool
if !bmHost.DeletionTimestamp.IsZero() && bmHost.Spec.ConsumerRef == nil {
bmHost.Spec.Status.ProvisioningState = infrav1.StateDeleting
needsUpdate = true
if !bmHost.DeletionTimestamp.IsZero() {
conditions.MarkFalse(
bmHost,
infrav1.HostReadyCondition,
infrav1.DeletionInProgressReason,
clusterv1.ConditionSeverityInfo,
"Host is not ready because it is being deleted",
)
conditions.SetSummary(bmHost)

if bmHost.Spec.ConsumerRef == nil {
bmHost.Spec.Status.ProvisioningState = infrav1.StateDeleting
}
} else if bmHost.NeedsProvisioning() {
bmHost.Spec.Status.ProvisioningState = infrav1.StatePreparing
needsUpdate = true
}
if needsUpdate {
err := r.Update(ctx, bmHost)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to add finalizer: %w", err)
}

if err := r.Update(ctx, bmHost); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to update host: %w", err)
}

return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
Expand Down

0 comments on commit d117e35

Please sign in to comment.