From c498cee2d84a499457f53ae52fa0e9620817441a Mon Sep 17 00:00:00 2001 From: yaroslavborbat Date: Tue, 3 Dec 2024 15:44:41 +0300 Subject: [PATCH] fix Signed-off-by: yaroslavborbat --- api/core/v1alpha2/virtual_image.go | 5 ++++- .../generated/openapi/zz_generated.openapi.go | 2 +- crds/virtualimages.yaml | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/api/core/v1alpha2/virtual_image.go b/api/core/v1alpha2/virtual_image.go index 7c5b0946a..1f13cf09c 100644 --- a/api/core/v1alpha2/virtual_image.go +++ b/api/core/v1alpha2/virtual_image.go @@ -66,11 +66,14 @@ type VirtualImageList struct { Items []VirtualImage `json:"items"` } +// +kubebuilder:validation:XValidation:rule="self.storage == 'ContainerRegistry' ? !has(self.persistentVolumeClaim) && has(self.dataSource): true",message="The storage type ContainerRegistry should contain only the dataSource." +// +kubebuilder:validation:XValidation:rule="self.storage == 'PersistentVolumeClaim' ? !has(self.dataSource) && has(self.persistentVolumeClaim): true",message="The storage type PersistentVolumeClaim should contain only the persistentVolumeClaim." +// +kubebuilder:validation:XValidation:rule="self.storage == 'Kubernetes' ? !has(self.dataSource) && has(self.persistentVolumeClaim): true",message="The storage type Kubernetes should contain only the persistentVolumeClaim." type VirtualImageSpec struct { // +kubebuilder:default:=ContainerRegistry Storage StorageType `json:"storage"` PersistentVolumeClaim VirtualImagePersistentVolumeClaim `json:"persistentVolumeClaim,omitempty"` - DataSource VirtualImageDataSource `json:"dataSource"` + DataSource VirtualImageDataSource `json:"dataSource,omitempty"` } type VirtualImageStatus struct { diff --git a/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go b/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go index d769f5487..55e5479bb 100644 --- a/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go +++ b/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go @@ -2937,7 +2937,7 @@ func schema_virtualization_api_core_v1alpha2_VirtualImageSpec(ref common.Referen }, }, }, - Required: []string{"storage", "dataSource"}, + Required: []string{"storage"}, }, }, Dependencies: []string{ diff --git a/crds/virtualimages.yaml b/crds/virtualimages.yaml index 714b55b6b..840528ac6 100644 --- a/crds/virtualimages.yaml +++ b/crds/virtualimages.yaml @@ -240,9 +240,25 @@ spec: - PersistentVolumeClaim type: string required: - - dataSource - storage type: object + x-kubernetes-validations: + - message: + The storage type ContainerRegistry should contain only the + dataSource. + rule: + "self.storage == 'ContainerRegistry' ? !has(self.persistentVolumeClaim) + && has(self.dataSource): true" + - message: + The storage type PersistentVolumeClaim should contain only + the persistentVolumeClaim. + rule: + "self.storage == 'PersistentVolumeClaim' ? !has(self.dataSource) + && has(self.persistentVolumeClaim): true" + - message: The storage type Kubernetes should contain only the persistentVolumeClaim. + rule: + "self.storage == 'Kubernetes' ? !has(self.dataSource) && has(self.persistentVolumeClaim): + true" status: properties: cdrom: