From e4180c56c5af996b66f7d874aacc670bd78a7b63 Mon Sep 17 00:00:00 2001 From: Shyamsundar Ranganathan Date: Fri, 15 Nov 2024 12:07:40 -0500 Subject: [PATCH] Update unused messages for Volrep and remove PVCs from status once secondary Signed-off-by: Shyamsundar Ranganathan --- .../volumereplicationgroup_controller.go | 15 +++++---- internal/controller/vrg_volrep.go | 33 +++++++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/internal/controller/volumereplicationgroup_controller.go b/internal/controller/volumereplicationgroup_controller.go index 54c533fc1..fd6c32200 100644 --- a/internal/controller/volumereplicationgroup_controller.go +++ b/internal/controller/volumereplicationgroup_controller.go @@ -1541,15 +1541,13 @@ func (v *VRGInstance) updateVRGConditions() { func (v *VRGInstance) vrgReadyStatus(reason string) *metav1.Condition { v.log.Info("Marking VRG ready with replicating reason", "reason", reason) - unusedMsg := "No PVCs are protected using VolumeReplication scheme" - if v.instance.Spec.Sync != nil { - unusedMsg = "No PVCs are protected, no PVCs found matching the selector" - } - if v.instance.Spec.ReplicationState == ramendrv1alpha1.Secondary { msg := "PVCs in the VolumeReplicationGroup group are replicating" if reason == VRGConditionReasonUnused { - msg = unusedMsg + msg = "PVC protection as secondary is complete, or no PVCs needed protection using VolumeReplication scheme" + if v.instance.Spec.Sync != nil { + msg = "PVC protection as secondary is complete, or no PVCs needed protection" + } } else { reason = VRGConditionReasonReplicating } @@ -1560,7 +1558,10 @@ func (v *VRGInstance) vrgReadyStatus(reason string) *metav1.Condition { // VRG as primary msg := "PVCs in the VolumeReplicationGroup are ready for use" if reason == VRGConditionReasonUnused { - msg = unusedMsg + msg = "No PVCs are protected using VolumeReplication scheme" + if v.instance.Spec.Sync != nil { + msg = "No PVCs are protected, no PVCs found matching the selector" + } } return newVRGAsPrimaryReadyCondition(v.instance.Generation, reason, msg) diff --git a/internal/controller/vrg_volrep.go b/internal/controller/vrg_volrep.go index ef1110e37..c7d3a189d 100644 --- a/internal/controller/vrg_volrep.go +++ b/internal/controller/vrg_volrep.go @@ -114,7 +114,7 @@ func (v *VRGInstance) reconcileVolRepsAsPrimary() { // reconcileVolRepsAsSecondary reconciles VolumeReplication resources for the VRG as secondary // -//nolint:gocognit,cyclop +//nolint:gocognit,cyclop,funlen func (v *VRGInstance) reconcileVolRepsAsSecondary() bool { requeue := false @@ -122,10 +122,12 @@ func (v *VRGInstance) reconcileVolRepsAsSecondary() bool { pvc := &v.volRepPVCs[idx] log := logWithPvcName(v.log, pvc) - // Potentially for PVCs that are not deleted + // Potentially for PVCs that are not deleted, e.g Failover of STS without required auto delete options if !containsString(pvc.Finalizers, PvcVRFinalizerProtected) { log.Info("pvc does not contain VR protection finalizer. Skipping it") + v.pvcStatusDeleteIfPresent(pvc.Namespace, pvc.Name, log) + continue } @@ -148,7 +150,7 @@ func (v *VRGInstance) reconcileVolRepsAsSecondary() bool { vrMissing, requeueResult := v.reconcileMissingVR(pvc, log) if vrMissing || requeueResult { - v.requeue() + requeue = true continue } @@ -166,9 +168,13 @@ func (v *VRGInstance) reconcileVolRepsAsSecondary() bool { continue } - // Not removed from protectedPVC list - // cleanupProtectedPVCs - return v.undoPVCFinalizersAndPVRetention(pvc, log) + if v.undoPVCFinalizersAndPVRetention(pvc, log) { + requeue = true + + continue + } + + v.pvcStatusDeleteIfPresent(pvc.Namespace, pvc.Name, log) } return requeue @@ -2567,6 +2573,16 @@ func (v *VRGInstance) aggregateVolRepDataReadyCondition() *metav1.Condition { //nolint:funlen,gocognit,cyclop func (v *VRGInstance) aggregateVolRepDataProtectedCondition() *metav1.Condition { if len(v.volRepPVCs) == 0 { + if v.instance.Spec.ReplicationState == ramendrv1alpha1.Secondary { + if v.instance.Spec.Sync != nil { + return newVRGAsDataProtectedUnusedCondition(v.instance.Generation, + "PVC protection as secondary is complete, or no PVCs needed protection") + } + + return newVRGAsDataProtectedUnusedCondition(v.instance.Generation, + "PVC protection as secondary is complete, or no PVCs needed protection using VolumeReplication scheme") + } + if v.instance.Spec.Sync != nil { return newVRGAsDataProtectedUnusedCondition(v.instance.Generation, "No PVCs are protected, no PVCs found matching the selector") @@ -2649,6 +2665,11 @@ func (v *VRGInstance) aggregateVolRepDataProtectedCondition() *metav1.Condition // protecting condition, set the VRG level condition to protecting. If not, set // the VRG level condition to true. func (v *VRGInstance) aggregateVolRepClusterDataProtectedCondition() *metav1.Condition { + if v.instance.Spec.ReplicationState == ramendrv1alpha1.Secondary { + return newVRGClusterDataProtectedUnusedCondition(v.instance.Generation, + "Cluster data is not protected as Secondary") + } + if len(v.volRepPVCs) == 0 { if v.instance.Spec.Sync != nil { return newVRGAsDataProtectedUnusedCondition(v.instance.Generation,