Skip to content

Commit

Permalink
Clean up PVCs that are not owned by VRG but present in protected pvcs…
Browse files Browse the repository at this point in the history
… list

A PVC that was not bound and picked up by the PVC selector, may change
it's labels and hence not be protected in the future.

Such PVCs are added to the ProtectedPVC list initially, but if they remain
unbound and in the future are no longer selected by the label selector
remain in the protectedPVC list.

This commit addresses cleaning up of stale PVCs in the ProtectedPVC
list comparing it to the PVCs to protect and clearing out stale PVCs
from the ProtectedPVC list.

Signed-off-by: Annaraya Narasagond <[email protected]>
Signed-off-by: Annaraya Narasagond <[email protected]>
Co-authored-by: Annaraya Narasagond <[email protected]>
  • Loading branch information
asn1809 and Annaraya-Narasagond authored Apr 19, 2024
1 parent 6b4b19d commit cfdfbc7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions controllers/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,47 @@ func (v *VRGInstance) pvcsDeselectedUnprotect() error {
}
}

v.cleanupProtectedPVCs(pvcsVr, pvcsVs, log)

return nil
}

func (v *VRGInstance) cleanupProtectedPVCs(
pvcsVr, pvcsVs map[client.ObjectKey]corev1.PersistentVolumeClaim, log logr.Logger,
) {
if !v.ramenConfig.VolumeUnprotectionEnabled {
log.Info("Volume unprotection disabled")

return
}

if v.instance.Spec.Async != nil && !VolumeUnprotectionEnabledForAsyncVolRep {
log.Info("Volume unprotection disabled for async mode")

return
}
// clean up the PVCs that are part of protected pvcs but not in v.volReps and v.volSyncs
protectedPVCsFiltered := make([]ramendrv1alpha1.ProtectedPVC, 0)

for _, protectedPVC := range v.instance.Status.ProtectedPVCs {
pvcNamespacedName := client.ObjectKey{Namespace: protectedPVC.Namespace, Name: protectedPVC.Name}

if _, ok := pvcsVr[pvcNamespacedName]; ok {
protectedPVCsFiltered = append(protectedPVCsFiltered, protectedPVC)

continue
}

if _, ok := pvcsVs[pvcNamespacedName]; ok {
protectedPVCsFiltered = append(protectedPVCsFiltered, protectedPVC)

continue
}
}

v.instance.Status.ProtectedPVCs = protectedPVCsFiltered
}

// processAsSecondary reconciles the current instance of VRG as secondary
func (v *VRGInstance) processAsSecondary() ctrl.Result {
v.log.Info("Entering processing VolumeReplicationGroup as Secondary")
Expand Down

0 comments on commit cfdfbc7

Please sign in to comment.