From 26b9878f19739a2369fbf65fcdc5ec91676f04f0 Mon Sep 17 00:00:00 2001 From: yati1998 Date: Wed, 2 Apr 2025 17:08:29 +0530 Subject: [PATCH] Include matchExpression to be considered as selector This commit allows matchExpression as well as a part of selector while creating volumegroupsnapshots Signed-off-by: yati1998 --- pkg/common-controller/groupsnapshot_controller_helper.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/common-controller/groupsnapshot_controller_helper.go b/pkg/common-controller/groupsnapshot_controller_helper.go index 79f142c37..abbc48075 100644 --- a/pkg/common-controller/groupsnapshot_controller_helper.go +++ b/pkg/common-controller/groupsnapshot_controller_helper.go @@ -222,8 +222,15 @@ func (ctrl *csiSnapshotCommonController) getVolumesFromVolumeGroupSnapshot(group func (ctrl *csiSnapshotCommonController) getClaimsFromVolumeGroupSnapshot(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) ([]v1.PersistentVolumeClaim, error) { labelSelector := groupSnapshot.Spec.Source.Selector + // Convert LabelSelector to a string format + // LabelSelectorAsSelector checks for both matchLabels and matchExpression selectors. + selector, err := metav1.LabelSelectorAsSelector(labelSelector) + if err != nil { + return nil, fmt.Errorf("failed to convert label selector to selector: %v", err) + } + // Get PVC that has group snapshot label applied. - pvcList, err := ctrl.client.CoreV1().PersistentVolumeClaims(groupSnapshot.Namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: labels.Set(labelSelector.MatchLabels).String()}) + pvcList, err := ctrl.client.CoreV1().PersistentVolumeClaims(groupSnapshot.Namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String()}) if err != nil { return nil, fmt.Errorf("failed to list PVCs with label selector %s: %q", metav1.FormatLabelSelector(labelSelector), err) }