From 9df5951c12477decea3e6f12ab46586c0b588a0b Mon Sep 17 00:00:00 2001 From: oraz Date: Thu, 28 Sep 2023 16:19:38 +0300 Subject: [PATCH 1/2] Stop updating status when remediation is completed and a finalizer is missing When FAR doesn't include a finalizer after successful remediation then there is no need to update the status, since it will be removed soon. --- controllers/fenceagentsremediation_controller.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index 8c806581..810da0a9 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -247,6 +247,11 @@ func isTimedOutByNHC(far *v1alpha1.FenceAgentsRemediation) bool { // updateStatus updates the CR status, and returns an error if it fails func (r *FenceAgentsRemediationReconciler) updateStatus(ctx context.Context, far *v1alpha1.FenceAgentsRemediation) error { + // When FAR doesn't include a finalizer after successful remediation then there is no need to update the status, since it will be removed soon. + if !controllerutil.ContainsFinalizer(far, v1alpha1.FARFinalizer) && meta.IsStatusConditionTrue(far.Status.Conditions, v1alpha1.FenceAgentActionSucceededType) && + meta.IsStatusConditionTrue(far.Status.Conditions, commonConditions.SucceededType) { + return nil + } if err := r.Client.Status().Update(ctx, far); err != nil { if !apiErrors.IsConflict(err) { r.Log.Error(err, "failed to update far status in case on a non conflict") From a046ac6e488a11f76df94defeb7239061d6d9307 Mon Sep 17 00:00:00 2001 From: oraz Date: Wed, 4 Oct 2023 18:49:14 +0300 Subject: [PATCH 2/2] Skip update status when the CR is about to be garbage collected Cleaner condition using deletionTimestamp ratherthan CR conditions status --- controllers/fenceagentsremediation_controller.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index 810da0a9..53a5df02 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -247,9 +247,9 @@ func isTimedOutByNHC(far *v1alpha1.FenceAgentsRemediation) bool { // updateStatus updates the CR status, and returns an error if it fails func (r *FenceAgentsRemediationReconciler) updateStatus(ctx context.Context, far *v1alpha1.FenceAgentsRemediation) error { - // When FAR doesn't include a finalizer after successful remediation then there is no need to update the status, since it will be removed soon. - if !controllerutil.ContainsFinalizer(far, v1alpha1.FARFinalizer) && meta.IsStatusConditionTrue(far.Status.Conditions, v1alpha1.FenceAgentActionSucceededType) && - meta.IsStatusConditionTrue(far.Status.Conditions, commonConditions.SucceededType) { + // When CR doesn't include a finalizer and the CR deletionTimestamp exsists + // then we can skip update, since it will be removed soon. + if !controllerutil.ContainsFinalizer(far, v1alpha1.FARFinalizer) && !far.ObjectMeta.DeletionTimestamp.IsZero() { return nil } if err := r.Client.Status().Update(ctx, far); err != nil {