From 4a8a7444371ba2d5039f732ec2100571a1adbe9c Mon Sep 17 00:00:00 2001 From: everettraven Date: Tue, 22 Oct 2024 10:43:11 -0400 Subject: [PATCH] wip: first pass at API changes from review Signed-off-by: everettraven --- api/core/v1alpha1/clustercatalog_types.go | 9 +++++---- api/core/v1alpha1/zz_generated.deepcopy.go | 3 +-- ...m.operatorframework.io_clustercatalogs.yaml | 18 +++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/api/core/v1alpha1/clustercatalog_types.go b/api/core/v1alpha1/clustercatalog_types.go index 895f4068..1f64d794 100644 --- a/api/core/v1alpha1/clustercatalog_types.go +++ b/api/core/v1alpha1/clustercatalog_types.go @@ -74,7 +74,6 @@ type ClusterCatalogList struct { } // ClusterCatalogSpec defines the desired state of ClusterCatalog -// +kubebuilder:validation:XValidation:rule="!has(self.source.image.pollInterval) || (self.source.image.ref.find('@sha256:') == \"\")",message="cannot specify PollInterval while using digest-based image" type ClusterCatalogSpec struct { // source is a required field that allows the user to define the source of a Catalog that contains catalog metadata in the File-Based Catalog (FBC) format. // @@ -86,6 +85,7 @@ type ClusterCatalogSpec struct { // ref: quay.io/operatorhubio/catalog:latest // // For more information on FBC, see https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs + // +kubebuilder:validation:Required Source CatalogSource `json:"source"` // priority is an optional field that allows the user to define a priority for a ClusterCatalog. @@ -168,7 +168,7 @@ type ClusterCatalogURLs 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="has(self.type) && self.type == 'Image' ? has(self.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. // @@ -208,17 +208,18 @@ type ResolvedCatalogSource struct { // ResolvedImageSource provides information about the resolved source of a Catalog sourced from an image. type ResolvedImageSource struct { // ref contains the resolved sha256 image ref containing Catalog contents. + // +kubebuilder:validation:Required Ref string `json:"ref"` - // lastSuccessfulPollAttempt is the time when the resolved source was last successfully polled for new content. - LastSuccessfulPollAttempt metav1.Time `json:"lastSuccessfulPollAttempt"` } // ImageSource enables users to define the information required for sourcing a Catalog from an OCI image +// +kubebuilder:validation:XValidation:rule="!has(self.pollInterval) || (self.ref.find('@sha256:') == \"\")",message="cannot specify PollInterval while using digest-based image" type ImageSource struct { // ref is a required field that allows the user to define the reference to a container image containing Catalog contents. // Examples: // ref: quay.io/operatorhubio/catalog:latest # image reference // ref: quay.io/operatorhubio/catalog@sha256:c7392b4be033da629f9d665fec30f6901de51ce3adebeff0af579f311ee5cf1b # image reference with sha256 digest + // +kubebuilder:validation:Required Ref string `json:"ref"` // pollInterval is an optional field that allows the user to set the interval at which the image source should be polled for new content. // It must be specified as a duration. diff --git a/api/core/v1alpha1/zz_generated.deepcopy.go b/api/core/v1alpha1/zz_generated.deepcopy.go index 24f7bbfc..a47463fa 100644 --- a/api/core/v1alpha1/zz_generated.deepcopy.go +++ b/api/core/v1alpha1/zz_generated.deepcopy.go @@ -194,7 +194,7 @@ func (in *ResolvedCatalogSource) DeepCopyInto(out *ResolvedCatalogSource) { if in.Image != nil { in, out := &in.Image, &out.Image *out = new(ResolvedImageSource) - (*in).DeepCopyInto(*out) + **out = **in } } @@ -211,7 +211,6 @@ func (in *ResolvedCatalogSource) DeepCopy() *ResolvedCatalogSource { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResolvedImageSource) DeepCopyInto(out *ResolvedImageSource) { *out = *in - in.LastSuccessfulPollAttempt.DeepCopyInto(&out.LastSuccessfulPollAttempt) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolvedImageSource. diff --git a/config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml b/config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml index a3a10dc9..937a2dd2 100644 --- a/config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml +++ b/config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml @@ -118,6 +118,11 @@ spec: required: - ref type: object + x-kubernetes-validations: + - message: cannot specify PollInterval while using digest-based + image + rule: '!has(self.pollInterval) || (self.ref.find(''@sha256:'') + == "")' type: description: |- type is a required reference to the type of source the catalog is sourced from. @@ -134,14 +139,11 @@ spec: type: object x-kubernetes-validations: - message: source type 'Image' requires image field - rule: self.type == 'Image' && has(self.image) + rule: 'has(self.type) && self.type == ''Image'' ? has(self.image) + : !has(self.image)' required: - source type: object - x-kubernetes-validations: - - message: cannot specify PollInterval while using digest-based image - rule: '!has(self.source.image.pollInterval) || (self.source.image.ref.find(''@sha256:'') - == "")' status: description: ClusterCatalogStatus defines the observed state of ClusterCatalog properties: @@ -243,17 +245,11 @@ spec: description: image is a field containing resolution information for a catalog sourced from an image. properties: - lastSuccessfulPollAttempt: - description: lastSuccessfulPollAttempt is the time when the - resolved source was last successfully polled for new content. - format: date-time - type: string ref: description: ref contains the resolved sha256 image ref containing Catalog contents. type: string required: - - lastSuccessfulPollAttempt - ref type: object type: