Skip to content

Commit

Permalink
Don't return error in UpdateConditions
Browse files Browse the repository at this point in the history
The function has an error when unknown agent has been found. Thus, there is no need to return and check it from reconcile, since it is not an error from trying to update it. FAR can simply log informative error when it was called when unknown ConditionsChangeReason
  • Loading branch information
razo7 committed Jan 3, 2024
1 parent 60b9d54 commit 99c94ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
12 changes: 4 additions & 8 deletions controllers/fenceagentsremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct
}
if !valid {
r.Log.Error(err, "Didn't find a node matching the CR's name", "CR's Name", req.Name)
err := utils.UpdateConditions(utils.RemediationFinishedNodeNotFound, far, r.Log)
utils.UpdateConditions(utils.RemediationFinishedNodeNotFound, far, r.Log)
return emptyResult, err
}

// Check NHC timeout annotation
if isTimedOutByNHC(far) {
r.Log.Info("FAR remediation was stopped by Node Healthcheck Operator")
r.Executor.Remove(far.GetUID())
err := utils.UpdateConditions(utils.RemediationInterruptedByNHC, far, r.Log)
utils.UpdateConditions(utils.RemediationInterruptedByNHC, far, r.Log)
return emptyResult, err
}

Expand All @@ -144,9 +144,7 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct
}
r.Log.Info("Finalizer was added", "CR Name", req.Name)

if err := utils.UpdateConditions(utils.RemediationStarted, far, r.Log); err != nil {
return emptyResult, err
}
utils.UpdateConditions(utils.RemediationStarted, far, r.Log)
return requeueImmediately, nil
} else if controllerutil.ContainsFinalizer(far, v1alpha1.FARFinalizer) && !far.ObjectMeta.DeletionTimestamp.IsZero() {
// Delete CR only when a finalizer and DeletionTimestamp are set
Expand Down Expand Up @@ -212,9 +210,7 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct
r.Log.Error(err, "Manual workload deletion has failed", "CR's Name", req.Name)
return emptyResult, err
}
if err := utils.UpdateConditions(utils.RemediationFinishedSuccessfully, far, r.Log); err != nil {
return emptyResult, err
}
utils.UpdateConditions(utils.RemediationFinishedSuccessfully, far, r.Log)

r.Executor.Remove(far.GetUID())
r.Log.Info("FenceAgentsRemediation CR has completed to remediate the node", "Node Name", req.Name)
Expand Down
6 changes: 1 addition & 5 deletions pkg/cli/cliexecuter.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ func (e *Executer) updateStatus(ctx context.Context, far *v1alpha1.FenceAgentsRe
reason = utils.FenceAgentFailed
}

err = utils.UpdateConditions(reason, far, e.log)
if err != nil {
e.log.Error(err, "failed to update conditions", "FAR uid", far.UID)
return err
}
utils.UpdateConditions(reason, far, e.log)
return e.Status().Update(ctx, far)
}
17 changes: 9 additions & 8 deletions pkg/utils/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ const (

// updateConditions updates the status conditions of a FenceAgentsRemediation object based on the provided ConditionsChangeReason.
// return an error if an unknown ConditionsChangeReason is provided
func UpdateConditions(reason ConditionsChangeReason, far *v1alpha1.FenceAgentsRemediation, log logr.Logger) error {
func UpdateConditions(reason ConditionsChangeReason, far *v1alpha1.FenceAgentsRemediation, log logr.Logger) {

var (
processingConditionStatus, fenceAgentActionSucceededConditionStatus, succeededConditionStatus metav1.ConditionStatus
conditionMessage string
)
conditionUpdateMessage := "Couldn't update FAR Status Conditions"
unknownError := fmt.Errorf("unknown ConditionsChangeReason")
currentConditions := &far.Status.Conditions
conditionHasBeenChanged := false

Expand All @@ -77,9 +79,9 @@ func UpdateConditions(reason ConditionsChangeReason, far *v1alpha1.FenceAgentsRe
case FenceAgentTimedOut:
conditionMessage = FenceAgentTimedOutConditionMessage
default:
err := fmt.Errorf("unknown ConditionsChangeReason:%s", reason)
log.Error(err, "couldn't update FAR Status Conditions")
return err
// couldn't be reached...
log.Error(unknownError, conditionUpdateMessage, "CR name", far.Name, "Reason", reason)
return
}
case RemediationStarted:
processingConditionStatus = metav1.ConditionTrue
Expand All @@ -94,9 +96,8 @@ func UpdateConditions(reason ConditionsChangeReason, far *v1alpha1.FenceAgentsRe
succeededConditionStatus = metav1.ConditionTrue
conditionMessage = RemediationFinishedSuccessfullyConditionMessage
default:
err := fmt.Errorf("unknown ConditionsChangeReason:%s", reason)
log.Error(err, "couldn't update FAR Status Conditions")
return err
log.Error(unknownError, conditionUpdateMessage, "CR name", far.Name, "Reason", reason)
return
}

// if the requested Status.Conditions.Processing is different then the current one, then update Status.Conditions.Processing value
Expand Down Expand Up @@ -138,5 +139,5 @@ func UpdateConditions(reason ConditionsChangeReason, far *v1alpha1.FenceAgentsRe
}
log.Info("Updating Status Condition", "processingConditionStatus", processingConditionStatus, "fenceAgentActionSucceededConditionStatus", fenceAgentActionSucceededConditionStatus, "succeededConditionStatus", succeededConditionStatus, "reason", string(reason), "LastUpdateTime", far.Status.LastUpdateTime)

return nil
return
}

0 comments on commit 99c94ce

Please sign in to comment.