Skip to content

Commit

Permalink
Clarify use of error message from isVRConditionMet()
Browse files Browse the repository at this point in the history
Use `errorMsg` for the error message returned from isVRConditionMet(), and
`msg` for the default successful message.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Nov 10, 2024
1 parent 88117f4 commit 847680b
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -1505,9 +1505,9 @@ func (v *VRGInstance) validateVRValidatedStatus(
func (v *VRGInstance) validateVRCompletedStatus(pvc *corev1.PersistentVolumeClaim, volRep *volrep.VolumeReplication,
state ramendrv1alpha1.ReplicationState,
) bool {
conditionMet, _, msg := isVRConditionMet(volRep, volrep.ConditionCompleted, metav1.ConditionTrue)
conditionMet, _, errorMsg := isVRConditionMet(volRep, volrep.ConditionCompleted, metav1.ConditionTrue)
if !conditionMet {
if msg == "" {
if errorMsg == "" {
var (
stateString string
action string
Expand All @@ -1522,13 +1522,13 @@ func (v *VRGInstance) validateVRCompletedStatus(pvc *corev1.PersistentVolumeClai
action = "demoted"
}

msg = fmt.Sprintf("VolumeReplication resource for pvc not %s to %s", action, stateString)
errorMsg = fmt.Sprintf("VolumeReplication resource for pvc not %s to %s", action, stateString)
}

v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)

v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", msg, volRep.GetName(), volRep.GetNamespace()))
v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", errorMsg, volRep.GetName(), volRep.GetNamespace()))

return false
}
Expand Down Expand Up @@ -1563,21 +1563,21 @@ func (v *VRGInstance) validateAdditionalVRStatusForSecondary(pvc *corev1.Persist
return v.checkResyncCompletionAsSecondary(pvc, volRep)
}

conditionMet, _, msg := isVRConditionMet(volRep, volrep.ConditionDegraded, metav1.ConditionTrue)
conditionMet, _, errorMsg := isVRConditionMet(volRep, volrep.ConditionDegraded, metav1.ConditionTrue)
if !conditionMet {
if msg == "" {
msg = "VolumeReplication resource for pvc is not in Degraded condition while resyncing"
if errorMsg == "" {
errorMsg = "VolumeReplication resource for pvc is not in Degraded condition while resyncing"
}

v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)

v.log.Info(fmt.Sprintf("%s (VolRep %s/%s)", msg, volRep.GetName(), volRep.GetNamespace()))
v.log.Info(fmt.Sprintf("%s (VolRep %s/%s)", errorMsg, volRep.GetName(), volRep.GetNamespace()))

return false
}

msg = "VolumeReplication resource for the pvc is syncing as Secondary"
msg := "VolumeReplication resource for the pvc is syncing as Secondary"
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonReplicating, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonReplicating, msg)

Expand All @@ -1590,35 +1590,35 @@ func (v *VRGInstance) validateAdditionalVRStatusForSecondary(pvc *corev1.Persist
func (v *VRGInstance) checkResyncCompletionAsSecondary(pvc *corev1.PersistentVolumeClaim,
volRep *volrep.VolumeReplication,
) bool {
conditionMet, _, msg := isVRConditionMet(volRep, volrep.ConditionResyncing, metav1.ConditionFalse)
conditionMet, _, errorMsg := isVRConditionMet(volRep, volrep.ConditionResyncing, metav1.ConditionFalse)
if !conditionMet {
if msg == "" {
msg = "VolumeReplication resource for pvc not syncing as Secondary"
if errorMsg == "" {
errorMsg = "VolumeReplication resource for pvc not syncing as Secondary"
}

v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)

v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", msg, volRep.GetName(), volRep.GetNamespace()))
v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", errorMsg, volRep.GetName(), volRep.GetNamespace()))

return false
}

conditionMet, _, msg = isVRConditionMet(volRep, volrep.ConditionDegraded, metav1.ConditionFalse)
conditionMet, _, errorMsg = isVRConditionMet(volRep, volrep.ConditionDegraded, metav1.ConditionFalse)
if !conditionMet {
if msg == "" {
msg = "VolumeReplication resource for pvc is not syncing and is degraded as Secondary"
if errorMsg == "" {
errorMsg = "VolumeReplication resource for pvc is not syncing and is degraded as Secondary"
}

v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, msg)
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg)

v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", msg, volRep.GetName(), volRep.GetNamespace()))
v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", errorMsg, volRep.GetName(), volRep.GetNamespace()))

return false
}

msg = "VolumeReplication resource for the pvc as Secondary is in sync with Primary"
msg := "VolumeReplication resource for the pvc as Secondary is in sync with Primary"
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonReplicated, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonDataProtected, msg)

Expand Down

0 comments on commit 847680b

Please sign in to comment.