From a8c7589d8de9af87365fecc7d59147a3092cc665 Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Tue, 30 Jan 2024 13:13:52 +0100 Subject: [PATCH 1/2] Handle NHC timed out event only once Log and emit event for "NHC timed out" condition only the first time. Signed-off-by: Carlo Lobrano --- controllers/machinedeletionremediation_controller.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/machinedeletionremediation_controller.go b/controllers/machinedeletionremediation_controller.go index ee49f826..47dd4c9f 100644 --- a/controllers/machinedeletionremediation_controller.go +++ b/controllers/machinedeletionremediation_controller.go @@ -133,9 +133,14 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re }() if r.isTimedOutByNHC(mdr) { - log.Info("NHC time out annotation found, stopping remediation") - commonevents.RemediationStoppedByNHC(r.Recorder, mdr) - _, err = r.updateConditions(remediationTimedOutByNhc, mdr) + updateRequired, err := r.updateConditions(remediationTimedOutByNhc, mdr) + if err == nil && updateRequired { + log.Info("NHC time out annotation found, stopping remediation") + commonevents.RemediationStoppedByNHC(r.Recorder, mdr) + } else { + // Status.Condition and event already handled, nothing to do + } + // return error only if updateConditions fails return ctrl.Result{}, err } From 8211914f5d9b23dc16188563acaa37668bc1b6ed Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Tue, 30 Jan 2024 14:02:46 +0100 Subject: [PATCH 2/2] Emit RemediationFinished event only once Emit RemediationFinished event only if the corresponding status is not already set, which means MDR already emitted the same evnt before. Signed-off-by: Carlo Lobrano --- .../machinedeletionremediation_controller.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/controllers/machinedeletionremediation_controller.go b/controllers/machinedeletionremediation_controller.go index 47dd4c9f..13b39cc9 100644 --- a/controllers/machinedeletionremediation_controller.go +++ b/controllers/machinedeletionremediation_controller.go @@ -133,15 +133,13 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re }() if r.isTimedOutByNHC(mdr) { - updateRequired, err := r.updateConditions(remediationTimedOutByNhc, mdr) - if err == nil && updateRequired { + if updateRequired, err := r.updateConditions(remediationTimedOutByNhc, mdr); err != nil { + return ctrl.Result{}, err + } else if updateRequired { log.Info("NHC time out annotation found, stopping remediation") commonevents.RemediationStoppedByNHC(r.Recorder, mdr) - } else { - // Status.Condition and event already handled, nothing to do } - // return error only if updateConditions fails - return ctrl.Result{}, err + return ctrl.Result{}, nil } if updateRequired, err := r.updateConditions(remediationStarted, mdr); err != nil { @@ -188,11 +186,12 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re } return ctrl.Result{}, err } else if isRestored { - _, err = r.updateConditions(remediationFinishedMachineDeleted, mdr) - if err == nil { + if updateRequired, err := r.updateConditions(remediationFinishedMachineDeleted, mdr); err != nil { + return ctrl.Result{}, err + } else if updateRequired { commonevents.RemediationFinished(r.Recorder, mdr) } - return ctrl.Result{}, err + return ctrl.Result{}, nil } log.Info("waiting for the nodes count to be re-provisioned") return ctrl.Result{RequeueAfter: 30 * time.Second}, nil