Skip to content

Commit

Permalink
restructure validation checks to only check for image source type
Browse files Browse the repository at this point in the history
Signed-off-by: Ankita Thomas <[email protected]>
  • Loading branch information
ankitathomas committed Oct 1, 2024
1 parent ce16296 commit 20dbb55
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
6 changes: 2 additions & 4 deletions api/core/v1alpha1/clustercatalog_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ type ClusterCatalogStatus struct {
// CatalogSource is a discriminated union of possible sources for a Catalog.
// CatalogSource contains the sourcing information for a Catalog
// +union
// +kubebuilder:validation:XValidation:rule="self.type != 'Image' || has(self.image)",message="source type 'Image' requires image field"
// +kubebuilder:validation:XValidation:rule="self.type == 'Image' || !has(self.image)",message="image field must only be set for source type 'Image'"
// +kubebuilder:validation:XValidation:rule="self.type == 'Image' && has(self.image)",message="source type 'Image' requires image field"
type CatalogSource struct {
// type is a required reference to the type of source the catalog is sourced from.
//
Expand All @@ -167,8 +166,7 @@ type CatalogSource struct {
// ResolvedCatalogSource is a discriminated union of resolution information for a Catalog.
// ResolvedCatalogSource contains the information about a sourced Catalog
// +union
// +kubebuilder:validation:XValidation:rule="self.type != 'Image' || has(self.image)",message="source type 'Image' requires image field"
// +kubebuilder:validation:XValidation:rule="self.type == 'Image' || !has(self.image)",message="image field must only be set for source type 'Image'"
// +kubebuilder:validation:XValidation:rule="self.type == 'Image' && has(self.image)",message="source type 'Image' requires image field"
type ResolvedCatalogSource struct {
// type is a reference to the type of source the catalog is sourced from.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ spec:
type: object
x-kubernetes-validations:
- message: source type 'Image' requires image field
rule: self.type != 'Image' || has(self.image)
- message: image field must only be set for source type 'Image'
rule: self.type == 'Image' || !has(self.image)
rule: self.type == 'Image' && has(self.image)
required:
- source
type: object
Expand Down Expand Up @@ -266,9 +264,7 @@ spec:
type: object
x-kubernetes-validations:
- message: source type 'Image' requires image field
rule: self.type != 'Image' || has(self.image)
- message: image field must only be set for source type 'Image'
rule: self.type == 'Image' || !has(self.image)
rule: self.type == 'Image' && has(self.image)
type: object
required:
- metadata
Expand Down

0 comments on commit 20dbb55

Please sign in to comment.