Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/controller/replication.storage/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"fmt"
"slices"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
Expand All @@ -42,7 +43,12 @@ func (r VolumeReplicationReconciler) getPVCDataSource(ctx context.Context, logge
}
// Validate PVC in bound state
if pvc.Status.Phase != corev1.ClaimBound {
return pvc, nil, fmt.Errorf("PVC %q is not bound to any PV", req.Name)
return nil, nil, fmt.Errorf("PVC %q is not bound to any PV", req.Name)
}

// Validate if PVC is not already marked for deletion
if !pvc.DeletionTimestamp.IsZero() && !slices.Contains(pvc.Finalizers, pvcReplicationFinalizer) {
return nil, nil, fmt.Errorf("PVC %q is marked for deletion, cannot be part of VolumeReplication", req.Name)
}

// Get PV object for the PVC
Expand All @@ -54,7 +60,7 @@ func (r VolumeReplicationReconciler) getPVCDataSource(ctx context.Context, logge
logger.Error(err, "PV not found", "PV Name", pvName)
}

return pvc, nil, err
return nil, nil, err
}

return pvc, pv, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,18 +537,38 @@ func (r *VolumeGroupReplicationReconciler) getMatchingPVCsFromSource(instance *r
return nil, "", err
}

// Update events if PVC is marked for deletion, but contains the pvc selector label of group
// Update events if PVC is marked for deletion, but contains the pvc selector label of group and
// also remove the PVCs from the list if they are already marked for deletion before being part
// of the group
removeDeletingPVC := []corev1.PersistentVolumeClaim{}
for _, pvc := range pvcList.Items {
if !pvc.DeletionTimestamp.IsZero() {
// PVC is marked for deletion, but not deleted because it is still a part of
// group using label selectors. Add an event to the PVC mentioning the same
msg := fmt.Sprintf("PersistentVolumeClaim is part of the group(%s/%s) using matching label selector. Remove label from PersistentVolumeClaim (%s/%s) to allow deletion",
instance.Namespace, instance.Name, pvc.Namespace, pvc.Name)
r.Recorder.Event(&pvc, "Warning", "PersistentVolumeClaimDeletionBlocked", msg)
if slices.Contains(pvc.Finalizers, vgrReplicationFinalizer) {
// PVC is marked for deletion, but not deleted because it is still a part of
// group using label selectors. Add an event to the PVC mentioning the same
msg := fmt.Sprintf("PersistentVolumeClaim is part of the group(%s/%s) using matching label selector. Remove label from PersistentVolumeClaim (%s/%s) to allow deletion",
instance.Namespace, instance.Name, pvc.Namespace, pvc.Name)
r.Recorder.Event(&pvc, "Warning", "PersistentVolumeClaimDeletionBlocked", msg)
} else {
removeDeletingPVC = append(removeDeletingPVC, pvc)
}
}
}

updatedPVCList := []corev1.PersistentVolumeClaim{}
if len(removeDeletingPVC) > 0 {
for _, pvc := range pvcList.Items {
if !slices.ContainsFunc(removeDeletingPVC, func(removePVC corev1.PersistentVolumeClaim) bool {
return removePVC.Name == pvc.Name
}) {
updatedPVCList = append(updatedPVCList, pvc)
}
}
} else {
updatedPVCList = pvcList.Items
}

return pvcList.Items, selector.String(), nil
return updatedPVCList, selector.String(), nil
}

// getPVHandles fetches the PV handles for the respective PVCs
Expand Down