From 7da1b7008c3727b34ba880144ea2e7fca636b19b Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 6 Aug 2024 11:58:56 +0200 Subject: [PATCH] add name length validation for driver Choosing an arbitary length which is 54 for the csi driver name and adding a validation to block CR creation if the name is having more chars. Signed-off-by: Madhu Rajanna --- api/v1alpha1/driver_types.go | 1 + config/crd/bases/csi.ceph.io_drivers.yaml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/api/v1alpha1/driver_types.go b/api/v1alpha1/driver_types.go index bb58b0d1..33efdbcf 100644 --- a/api/v1alpha1/driver_types.go +++ b/api/v1alpha1/driver_types.go @@ -371,6 +371,7 @@ type DriverStatus struct { //+kubebuilder:subresource:status // +kubebuilder:validation:XValidation:rule=self.metadata.name.matches('^(.+\\.)?(rbd|cephfs|nfs)?\\.csi\\.ceph\\.com$'),message=".metadata.name must match: '[.](rbd|cephfs|nfs).csi.ceph.com'" +// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 54",message=".metadata.name must be no more than 54 characters" // Driver is the Schema for the drivers API type Driver struct { metav1.TypeMeta `json:",inline"` diff --git a/config/crd/bases/csi.ceph.io_drivers.yaml b/config/crd/bases/csi.ceph.io_drivers.yaml index 02f6676b..5b7b29fd 100644 --- a/config/crd/bases/csi.ceph.io_drivers.yaml +++ b/config/crd/bases/csi.ceph.io_drivers.yaml @@ -6788,6 +6788,8 @@ spec: x-kubernetes-validations: - message: '.metadata.name must match: ''[.](rbd|cephfs|nfs).csi.ceph.com''' rule: self.metadata.name.matches('^(.+\\.)?(rbd|cephfs|nfs)?\\.csi\\.ceph\\.com$') + - message: .metadata.name must be no more than 54 characters + rule: self.metadata.name.size() <= 54 served: true storage: true subresources: