Skip to content

Commit 5dbbccb

Browse files
committed
add check to avoid replicating terminating pvc
add check to avoid PVCs that are already in terminating state to be a part of VR/VGR. Signed-off-by: Nikhil-Ladha <nikhilladha1999@gmail.com>
1 parent 1399d94 commit 5dbbccb

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

internal/controller/replication.storage/pvc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func (r VolumeReplicationReconciler) getPVCDataSource(ctx context.Context, logge
4545
return pvc, nil, fmt.Errorf("PVC %q is not bound to any PV", req.Name)
4646
}
4747

48+
// Validate if PVC is not already marked for deletion
49+
if !pvc.DeletionTimestamp.IsZero() {
50+
return pvc, nil, fmt.Errorf("PVC %q is marked for deletion, cannot be part of VolumeReplication", req.Name)
51+
}
52+
4853
// Get PV object for the PVC
4954
pvName := pvc.Spec.VolumeName
5055
pv := &corev1.PersistentVolume{}

internal/controller/replication.storage/volumegroupreplication_controller.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,18 +537,38 @@ func (r *VolumeGroupReplicationReconciler) getMatchingPVCsFromSource(instance *r
537537
return nil, "", err
538538
}
539539

540-
// Update events if PVC is marked for deletion, but contains the pvc selector label of group
540+
// Update events if PVC is marked for deletion, but contains the pvc selector label of group and
541+
// also remove the PVCs from the list if they are already marked for deletion before being part
542+
// of the group
543+
removeDeletingPVC := []corev1.PersistentVolumeClaim{}
541544
for _, pvc := range pvcList.Items {
542545
if !pvc.DeletionTimestamp.IsZero() {
543-
// PVC is marked for deletion, but not deleted because it is still a part of
544-
// group using label selectors. Add an event to the PVC mentioning the same
545-
msg := fmt.Sprintf("PersistentVolumeClaim is part of the group(%s/%s) using matching label selector. Remove label from PersistentVolumeClaim (%s/%s) to allow deletion",
546-
instance.Namespace, instance.Name, pvc.Namespace, pvc.Name)
547-
r.Recorder.Event(&pvc, "Warning", "PersistentVolumeClaimDeletionBlocked", msg)
546+
if slices.Contains(pvc.Finalizers, vgrReplicationFinalizer) {
547+
// PVC is marked for deletion, but not deleted because it is still a part of
548+
// group using label selectors. Add an event to the PVC mentioning the same
549+
msg := fmt.Sprintf("PersistentVolumeClaim is part of the group(%s/%s) using matching label selector. Remove label from PersistentVolumeClaim (%s/%s) to allow deletion",
550+
instance.Namespace, instance.Name, pvc.Namespace, pvc.Name)
551+
r.Recorder.Event(&pvc, "Warning", "PersistentVolumeClaimDeletionBlocked", msg)
552+
} else {
553+
removeDeletingPVC = append(removeDeletingPVC, pvc)
554+
}
555+
}
556+
}
557+
558+
updatedPVCList := []corev1.PersistentVolumeClaim{}
559+
if len(removeDeletingPVC) > 0 {
560+
for _, pvc := range pvcList.Items {
561+
if !slices.ContainsFunc(removeDeletingPVC, func(removePVC corev1.PersistentVolumeClaim) bool {
562+
return removePVC.Name == pvc.Name
563+
}) {
564+
updatedPVCList = append(updatedPVCList, pvc)
565+
}
548566
}
567+
} else {
568+
updatedPVCList = pvcList.Items
549569
}
550570

551-
return pvcList.Items, selector.String(), nil
571+
return updatedPVCList, selector.String(), nil
552572
}
553573

554574
// getPVHandles fetches the PV handles for the respective PVCs

0 commit comments

Comments
 (0)