From 037985a4d2921b5c7c10845ac585c84d205f4edf Mon Sep 17 00:00:00 2001 From: Leela Venkaiah G Date: Thu, 23 Dec 2021 12:16:57 +0530 Subject: [PATCH] fix: validate deviceClass name to be usable in storageClass Fixes: #40 Signed-off-by: Leela Venkaiah G --- api/v1alpha1/lvmcluster_types.go | 5 +++++ config/crd/bases/lvm.topolvm.io_lvmclusters.yaml | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/lvmcluster_types.go b/api/v1alpha1/lvmcluster_types.go index 1e908a0b3..846dcde28 100644 --- a/api/v1alpha1/lvmcluster_types.go +++ b/api/v1alpha1/lvmcluster_types.go @@ -35,6 +35,11 @@ type LVMClusterSpec struct { type DeviceClass struct { // Name of the class, the VG and possibly the storageclass. + // Validations to confirm that this field can be used as metadata.name field in storageclass + // ref: https://github.com/kubernetes/apimachinery/blob/de7147/pkg/util/validation/validation.go#L209 + // +kubebuilder:validation:MaxLength=245 + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" Name string `json:"name,omitempty"` // DeviceSelector is a set of rules that should match for a device to be included in this TopoLVMCluster diff --git a/config/crd/bases/lvm.topolvm.io_lvmclusters.yaml b/config/crd/bases/lvm.topolvm.io_lvmclusters.yaml index e039c776f..c63e704c1 100644 --- a/config/crd/bases/lvm.topolvm.io_lvmclusters.yaml +++ b/config/crd/bases/lvm.topolvm.io_lvmclusters.yaml @@ -46,7 +46,12 @@ spec: for a device to be included in this TopoLVMCluster type: object name: - description: Name of the class, the VG and possibly the storageclass. + description: 'Name of the class, the VG and possibly the storageclass. + Validations to confirm that this field can be used as metadata.name + field in storageclass ref: https://github.com/kubernetes/apimachinery/blob/de7147/pkg/util/validation/validation.go#L209' + maxLength: 245 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ type: string nodeSelector: description: NodeSelector chooses nodes