Skip to content

Commit aa98b96

Browse files
ELENAGERBenamarMk
authored andcommitted
Clean stale protected PVCs from VRG on primary before reconciliation
Signed-off-by: Elena Gershkovich <[email protected]>
1 parent 0f85cf8 commit aa98b96

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

internal/controller/volumereplicationgroup_controller.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,6 @@ func (v *VRGInstance) processAsPrimary() ctrl.Result {
13951395

13961396
v.resetKubeObjectsCaptureStatusIfRequired()
13971397

1398-
if err := v.pvcsDeselectedUnprotect(); err != nil {
1399-
return v.dataError(err, "PVCs deselected unprotect failed", v.result.Requeue)
1400-
}
1401-
14021398
if v.shouldRestoreClusterData() {
14031399
v.result.Requeue = true
14041400

@@ -1413,6 +1409,10 @@ func (v *VRGInstance) processAsPrimary() ctrl.Result {
14131409
}
14141410
}
14151411

1412+
if err := v.pvcsDeselectedUnprotect(); err != nil {
1413+
return v.dataError(err, "PVCs deselected unprotect failed", v.result.Requeue)
1414+
}
1415+
14161416
v.reconcileAsPrimary()
14171417

14181418
v.updateVRGDataReadyCondition()
@@ -1627,9 +1627,45 @@ func (v *VRGInstance) pvcsDeselectedUnprotect() error {
16271627
}
16281628
}
16291629

1630+
v.cleanupProtectedPVCs(pvcsVr, pvcsVs, log)
1631+
16301632
return nil
16311633
}
16321634

1635+
func (v *VRGInstance) cleanupProtectedPVCs(
1636+
pvcsVr, pvcsVs map[client.ObjectKey]corev1.PersistentVolumeClaim, log logr.Logger,
1637+
) {
1638+
if !v.ramenConfig.VolumeUnprotectionEnabled {
1639+
log.Info("Volume unprotection disabled")
1640+
1641+
return
1642+
}
1643+
1644+
// clean up the PVCs that are part of protected pvcs but not in v.volReps and v.volSyncs
1645+
protectedPVCsFiltered := make([]ramendrv1alpha1.ProtectedPVC, 0)
1646+
1647+
for _, protectedPVC := range v.instance.Status.ProtectedPVCs {
1648+
pvcNamespacedName := client.ObjectKey{Namespace: protectedPVC.Namespace, Name: protectedPVC.Name}
1649+
1650+
if _, ok := pvcsVr[pvcNamespacedName]; ok {
1651+
protectedPVCsFiltered = append(protectedPVCsFiltered, protectedPVC)
1652+
1653+
continue
1654+
}
1655+
1656+
if _, ok := pvcsVs[pvcNamespacedName]; ok {
1657+
protectedPVCsFiltered = append(protectedPVCsFiltered, protectedPVC)
1658+
1659+
continue
1660+
}
1661+
1662+
v.log.Info(fmt.Sprintf("Removing stale protected pvc %s/%s from VRG %s/%s",
1663+
protectedPVC.Namespace, protectedPVC.Name, v.instance.Namespace, v.instance.Name))
1664+
}
1665+
1666+
v.instance.Status.ProtectedPVCs = protectedPVCsFiltered
1667+
}
1668+
16331669
// processAsSecondary reconciles the current instance of VRG as secondary
16341670
func (v *VRGInstance) processAsSecondary() ctrl.Result {
16351671
v.log.Info("Entering processing VolumeReplicationGroup as Secondary")

0 commit comments

Comments
 (0)