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: