Skip to content

Commit

Permalink
WIP: Check VR Validated condition
Browse files Browse the repository at this point in the history
When deleting a primary VRG, we wait until the VR Completed condition is
met. However if a VR precondition failed, for example using a drpolicy
without flattening enabled when the PVC needs flattening, the VR will
never complete, so the vrg will never be deleted.

In csi-addons 0.10.0 we have a new Validated VR condition, set to true
if pre conditions are met, and false if not. This change handles this
new condition.

When deleting a primary VRG, we check the VR Validated condition:

- If the condition exists and is false, this VR will never complete and
  can be safely deleted. We return true, meaning that the VR is in the
  desired condition.

- Otherwise we continue normally to check the next conditions.

This change adds validation for the condition and log the status for
understanding if this is the right place to change.

Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Sep 23, 2024
1 parent 4560d3c commit 49f8871
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
39 changes: 36 additions & 3 deletions internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,12 +1411,21 @@ func (v *VRGInstance) checkVRStatus(pvc *corev1.PersistentVolumeClaim, volRep *v

// validateVRStatus validates if the VolumeReplication resource has the desired status for the
// current generation and returns true if so, false otherwise
// - When replication state is Primary, only Completed condition is checked.
// - When replication state is Secondary, all 3 conditions for Completed/Degraded/Resyncing is
// checked and ensured healthy.
// - When replication state is Primary, Validated and Completed conditions are checked.
// - When replication state is Secondary, Completed, Degraded and Resyncing conditions are checked and
// ensured healthy.
func (v *VRGInstance) validateVRStatus(pvc *corev1.PersistentVolumeClaim, volRep *volrep.VolumeReplication,
state ramendrv1alpha1.ReplicationState,
) bool {
// Check validated for primary during VRG deletion.
if state == ramendrv1alpha1.Primary && rmnutil.ResourceIsDeleted(v.instance) {
validated, ok := v.validateVRValidatedStatus(pvc, volRep)
// VR will never complete and can be deleted safely.
if !validated && ok {
return true
}
}

// Check completed for both primary and secondary.
if !v.validateVRCompletedStatus(pvc, volRep, state) {
return false
Expand All @@ -1439,6 +1448,30 @@ func (v *VRGInstance) validateVRStatus(pvc *corev1.PersistentVolumeClaim, volRep
return true
}

// validateVRValidatedStatus validates that VolumeReplicaion resource was validated and update the pvc
// DataReady and Protected conditions if not.
// Return 2 booleans
// - validated: true if the condition is true, otherwise false
// - ok: true if the check was succeesfull, false if we need to retry later
func (v *VRGInstance) validateVRValidatedStatus(
pvc *corev1.PersistentVolumeClaim,
volRep *volrep.VolumeReplication,
) (bool, bool) {
conditionMet, errorMsg := isVRConditionMet(volRep, volrep.ConditionValidated, metav1.ConditionTrue)
if !conditionMet {
defaultMsg := "VolumeReplication resource for pvc failed validation"
v.updatePVCDataReadyConditionHelper(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg,
defaultMsg)
v.updatePVCDataProtectedConditionHelper(pvc.Namespace, pvc.Name, VRGConditionReasonError, errorMsg,
defaultMsg)
v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", defaultMsg, volRep.GetName(), volRep.GetNamespace()))

return false, errorMsg == ""
}

return true, true
}

// validateVRCompletedStatus validates if the VolumeReplication resource Completed condition is met and update
// the PVC DataReady and Protected conditions.
// Returns true if the condtion is true, false if the condition is missing, stale, ubnknown, of false.
Expand Down
7 changes: 7 additions & 0 deletions internal/controller/vrg_volrep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,13 @@ func (v *vrgTest) promoteVolRepsAndDo(do func(int, int)) {

volRepStatus := volrep.VolumeReplicationStatus{
Conditions: []metav1.Condition{
{
Type: volrep.ConditionValidated,
Reason: volrep.PrerequisiteMet,
ObservedGeneration: volRep.Generation,
Status: metav1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: volrep.ConditionCompleted,
Reason: volrep.Promoted,
Expand Down

0 comments on commit 49f8871

Please sign in to comment.