Skip to content

Commit

Permalink
fix: record reconciliation failure after ShouldReconcileTortoiseNow (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Oct 4, 2023
1 parent 4cfa290 commit d7b8f45
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions controllers/tortoise_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
logger.Error(err, "failed to get tortoise", "tortoise", req.NamespacedName)
return ctrl.Result{}, err
}
defer func() {
tortoise = r.TortoiseService.RecordReconciliationFailure(tortoise, reterr, now)
_, err = r.TortoiseService.UpdateTortoiseStatus(ctx, tortoise, now)
if err != nil {
logger.Error(err, "update Tortoise status", "tortoise", req.NamespacedName)
}
}()

if !tortoise.ObjectMeta.DeletionTimestamp.IsZero() {
// Tortoise is deleted by user and waiting for finalizer.
Expand All @@ -116,6 +109,15 @@ func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
return ctrl.Result{RequeueAfter: requeueAfter}, nil
}

// Need to register defer after `ShouldReconcileTortoiseNow` because it updates the tortoise status in it.
defer func() {
tortoise = r.TortoiseService.RecordReconciliationFailure(tortoise, reterr, now)
_, err = r.TortoiseService.UpdateTortoiseStatus(ctx, tortoise, now)
if err != nil {
logger.Error(err, "update Tortoise status", "tortoise", req.NamespacedName)
}
}()

dm, err := r.DeploymentService.GetDeploymentOnTortoise(ctx, tortoise)
if err != nil {
logger.Error(err, "failed to get deployment", "tortoise", req.NamespacedName)
Expand Down

0 comments on commit d7b8f45

Please sign in to comment.