From cdec347512538c0d112d79ea661100cab3cc20a0 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 3 Oct 2024 22:24:24 +0200 Subject: [PATCH] fix(api): loosen Stage validation (#2644) Signed-off-by: Hidde Beydals --- api/v1alpha1/generated.proto | 3 +-- api/v1alpha1/stage_types.go | 3 +-- .../kargo/resources/crds/kargo.akuity.io_stages.yaml | 11 +++++------ .../gen/schema/stages.kargo.akuity.io_v1alpha1.json | 8 ++------ ui/src/gen/v1alpha1/generated_pb.ts | 3 +-- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/api/v1alpha1/generated.proto b/api/v1alpha1/generated.proto index b8d1244b2..1d4bc88f4 100644 --- a/api/v1alpha1/generated.proto +++ b/api/v1alpha1/generated.proto @@ -1479,8 +1479,7 @@ message StageList { // StageSpec describes the sources of Freight used by a Stage and how to // incorporate Freight into the Stage. // -// +kubebuilder:validation:XValidation:rule="(has(self.promotionTemplate) || has(self.promotionMechanisms))",message="one of promotionTemplate or promotionMechanisms must be specified" -// +kubebuilder:validation:XValidation:rule="(has(self.promotionTemplate) && !has(self.promotionMechanisms)) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))",message="only one of promotionTemplate or promotionMechanisms can be specified" +// +kubebuilder:validation:XValidation:rule="(!has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || ( has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))",message="at most one of promotionTemplate or promotionMechanisms can be specified" message StageSpec { // Shard is the name of the shard that this Stage belongs to. This is an // optional field. If not specified, the Stage will belong to the default diff --git a/api/v1alpha1/stage_types.go b/api/v1alpha1/stage_types.go index 1c7d33051..fcd30b9e3 100644 --- a/api/v1alpha1/stage_types.go +++ b/api/v1alpha1/stage_types.go @@ -168,8 +168,7 @@ func (s *Stage) GetStatus() *StageStatus { // StageSpec describes the sources of Freight used by a Stage and how to // incorporate Freight into the Stage. // -// +kubebuilder:validation:XValidation:rule="(has(self.promotionTemplate) || has(self.promotionMechanisms))",message="one of promotionTemplate or promotionMechanisms must be specified" -// +kubebuilder:validation:XValidation:rule="(has(self.promotionTemplate) && !has(self.promotionMechanisms)) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))",message="only one of promotionTemplate or promotionMechanisms can be specified" +// +kubebuilder:validation:XValidation:rule="(!has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || ( has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))",message="at most one of promotionTemplate or promotionMechanisms can be specified" type StageSpec struct { // Shard is the name of the shard that this Stage belongs to. This is an // optional field. If not specified, the Stage will belong to the default diff --git a/charts/kargo/resources/crds/kargo.akuity.io_stages.yaml b/charts/kargo/resources/crds/kargo.akuity.io_stages.yaml index f58c9ce24..adf600535 100644 --- a/charts/kargo/resources/crds/kargo.akuity.io_stages.yaml +++ b/charts/kargo/resources/crds/kargo.akuity.io_stages.yaml @@ -1051,12 +1051,11 @@ spec: - requestedFreight type: object x-kubernetes-validations: - - message: one of promotionTemplate or promotionMechanisms must be specified - rule: (has(self.promotionTemplate) || has(self.promotionMechanisms)) - - message: only one of promotionTemplate or promotionMechanisms can be - specified - rule: (has(self.promotionTemplate) && !has(self.promotionMechanisms)) - || (!has(self.promotionTemplate) && has(self.promotionMechanisms)) + - message: at most one of promotionTemplate or promotionMechanisms can + be specified + rule: (!has(self.promotionTemplate) && !has(self.promotionMechanisms) + ) || ( has(self.promotionTemplate) && !has(self.promotionMechanisms) + ) || (!has(self.promotionTemplate) && has(self.promotionMechanisms)) status: description: Status describes the Stage's current and recent Freight, health, and more. diff --git a/ui/src/gen/schema/stages.kargo.akuity.io_v1alpha1.json b/ui/src/gen/schema/stages.kargo.akuity.io_v1alpha1.json index f2d8e2f15..d67635a83 100644 --- a/ui/src/gen/schema/stages.kargo.akuity.io_v1alpha1.json +++ b/ui/src/gen/schema/stages.kargo.akuity.io_v1alpha1.json @@ -836,12 +836,8 @@ "type": "object", "x-kubernetes-validations": [ { - "message": "one of promotionTemplate or promotionMechanisms must be specified", - "rule": "(has(self.promotionTemplate) || has(self.promotionMechanisms))" - }, - { - "message": "only one of promotionTemplate or promotionMechanisms can be specified", - "rule": "(has(self.promotionTemplate) && !has(self.promotionMechanisms)) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))" + "message": "at most one of promotionTemplate or promotionMechanisms can be specified", + "rule": "(!has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || ( has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))" } ] }, diff --git a/ui/src/gen/v1alpha1/generated_pb.ts b/ui/src/gen/v1alpha1/generated_pb.ts index 9f58d0fca..d546a73da 100644 --- a/ui/src/gen/v1alpha1/generated_pb.ts +++ b/ui/src/gen/v1alpha1/generated_pb.ts @@ -4458,8 +4458,7 @@ export class StageList extends Message { * StageSpec describes the sources of Freight used by a Stage and how to * incorporate Freight into the Stage. * - * +kubebuilder:validation:XValidation:rule="(has(self.promotionTemplate) || has(self.promotionMechanisms))",message="one of promotionTemplate or promotionMechanisms must be specified" - * +kubebuilder:validation:XValidation:rule="(has(self.promotionTemplate) && !has(self.promotionMechanisms)) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))",message="only one of promotionTemplate or promotionMechanisms can be specified" + * +kubebuilder:validation:XValidation:rule="(!has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || ( has(self.promotionTemplate) && !has(self.promotionMechanisms) ) || (!has(self.promotionTemplate) && has(self.promotionMechanisms))",message="at most one of promotionTemplate or promotionMechanisms can be specified" * * @generated from message github.com.akuity.kargo.api.v1alpha1.StageSpec */