Skip to content

Commit 196734c

Browse files
committed
Improve RWX volumes with VM service VMs performace during validation in webhook.
1 parent 61f0a34 commit 196734c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

pkg/syncer/admissionhandler/validate_cnsfileaccessconfig.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
admissionv1 "k8s.io/api/admission/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/labels"
1112
"sigs.k8s.io/controller-runtime/pkg/client"
1213
cnsoperatorv1alpha1 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator"
1314

@@ -42,6 +43,25 @@ func validateCreateCnsFileAccessConfig(ctx context.Context, clientConfig *rest.C
4243
}
4344
}
4445

46+
// This validation is not required for PVCSI service account.
47+
isPvCSIServiceAccount, err := validatePvCSIServiceAccount(req.UserInfo.Username)
48+
if err != nil {
49+
// return AdmissionResponse result
50+
return &admissionv1.AdmissionResponse{
51+
Allowed: false,
52+
Result: &metav1.Status{
53+
Message: fmt.Sprintf("failed to validate user information: %v", err),
54+
},
55+
}
56+
}
57+
58+
// If user is PVCSI service account, allow this request.
59+
if isPvCSIServiceAccount {
60+
return &admissionv1.AdmissionResponse{
61+
Allowed: true,
62+
}
63+
}
64+
4565
vm := cnsFileAccessConfig.Spec.VMName
4666
pvc := cnsFileAccessConfig.Spec.PvcName
4767
namespace := cnsFileAccessConfig.Namespace
@@ -87,9 +107,14 @@ func cnsFileAccessConfigAlreadyExists(ctx context.Context, clientConfig *rest.Co
87107
return "", err
88108
}
89109

110+
// List only those CnsFileAccessConfig CRs which are not created by PVCSI.
111+
labelSelector := labels.SelectorFromSet(labels.Set{devopsUserLabelKey: "true"})
90112
// Get the list of all CnsFileAccessConfig CRs in the given namespace.
91113
cnsFileAccessConfigList := &cnsfileaccessconfigv1alpha1.CnsFileAccessConfigList{}
92-
err = cnsOperatorClient.List(ctx, cnsFileAccessConfigList, &client.ListOptions{Namespace: namespace})
114+
err = cnsOperatorClient.List(ctx, cnsFileAccessConfigList, &client.ListOptions{
115+
Namespace: namespace,
116+
LabelSelector: labelSelector,
117+
})
93118
if err != nil {
94119
log.Errorf("failed to list CnsFileAccessConfigList CRs from %s namesapace. Error: %+v",
95120
namespace, err)

0 commit comments

Comments
 (0)