Skip to content

Commit

Permalink
Clarify isVRConditionMet
Browse files Browse the repository at this point in the history
Rename msg to errorMsg and document that this is an error message,
if the we could not get the condition value, because it is missing,
stale, or unknown.

Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Sep 23, 2024
1 parent c653aa1 commit 4560d3c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,34 +1569,35 @@ func (v *VRGInstance) checkResyncCompletionAsSecondary(pvc *corev1.PersistentVol
return true
}

// isVRConditionMet returns true if the condition is met, and an error mesage if we could not get the
// condition value.
func isVRConditionMet(volRep *volrep.VolumeReplication,
conditionType string,
desiredStatus metav1.ConditionStatus,
) (bool, string) {
volRepCondition := findCondition(volRep.Status.Conditions, conditionType)
if volRepCondition == nil {
msg := fmt.Sprintf("Failed to get the %s condition from status of VolumeReplication resource.", conditionType)
errorMsg := fmt.Sprintf("Failed to get the %s condition from status of VolumeReplication resource.",
conditionType)

return false, msg
return false, errorMsg
}

if volRep.GetGeneration() != volRepCondition.ObservedGeneration {
msg := fmt.Sprintf("Stale generation for condition %s from status of VolumeReplication resource.", conditionType)
errorMsg := fmt.Sprintf("Stale generation for condition %s from status of VolumeReplication resource.",
conditionType)

return false, msg
return false, errorMsg
}

if volRepCondition.Status == metav1.ConditionUnknown {
msg := fmt.Sprintf("Unknown status for condition %s from status of VolumeReplication resource.", conditionType)
errorMsg := fmt.Sprintf("Unknown status for condition %s from status of VolumeReplication resource.",
conditionType)

return false, msg
return false, errorMsg
}

if volRepCondition.Status != desiredStatus {
return false, ""
}

return true, ""
return volRepCondition.Status == desiredStatus, ""
}

// Disabling unparam linter as currently every invokation of this
Expand Down

0 comments on commit 4560d3c

Please sign in to comment.