From 4a50b90871bfda592a084cecb4439d42813e098a Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Thu, 11 Apr 2024 14:30:12 +0200 Subject: [PATCH] crd: require unique hosts (#613) Require unique non-empty hosts for ingress and routegroup specs. Signed-off-by: Alexander Yastrebov --- docs/stack_crd.yaml | 7 ++++--- docs/stackset_crd.yaml | 4 ++++ pkg/apis/zalando.org/v1/types.go | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/stack_crd.yaml b/docs/stack_crd.yaml index 5af997b7..ea36809a 100644 --- a/docs/stack_crd.yaml +++ b/docs/stack_crd.yaml @@ -398,7 +398,9 @@ spec: hosts: items: type: string + minItems: 1 type: array + x-kubernetes-list-type: set metadata: description: EmbeddedObjectMetaWithAnnotations defines the metadata which can be attached to a resource. It's a slimmed down version @@ -684,9 +686,6 @@ spec: empty selector ({}) matches all namespaces. properties: matchExpressions: - description: matchExpressions is a list - of label selector requirements. The - requirements are ANDed. items: properties: key: @@ -7627,7 +7626,9 @@ spec: description: Hosts is the list of hostnames to add to the routegroup. items: type: string + minItems: 1 type: array + x-kubernetes-list-type: set lbAlgorithm: description: The load balancing algorithm used for the generated per stack backends. diff --git a/docs/stackset_crd.yaml b/docs/stackset_crd.yaml index cb33c793..4e18ba4e 100644 --- a/docs/stackset_crd.yaml +++ b/docs/stackset_crd.yaml @@ -78,7 +78,9 @@ spec: hosts: items: type: string + minItems: 1 type: array + x-kubernetes-list-type: set metadata: description: EmbeddedObjectMetaWithAnnotations defines the metadata which can be attached to a resource. It's a slimmed down version @@ -192,7 +194,9 @@ spec: description: Hosts is the list of hostnames to add to the routegroup. items: type: string + minItems: 1 type: array + x-kubernetes-list-type: set lbAlgorithm: description: The load balancing algorithm used for the generated per stack backends. diff --git a/pkg/apis/zalando.org/v1/types.go b/pkg/apis/zalando.org/v1/types.go index aabe588a..f47f71b5 100644 --- a/pkg/apis/zalando.org/v1/types.go +++ b/pkg/apis/zalando.org/v1/types.go @@ -103,8 +103,10 @@ type EmbeddedObjectMeta struct { // +k8s:deepcopy-gen=true type StackSetIngressSpec struct { EmbeddedObjectMetaWithAnnotations `json:"metadata,omitempty"` - Hosts []string `json:"hosts"` - BackendPort intstr.IntOrString `json:"backendPort"` + // +kubebuilder:validation:MinItems=1 + // +listType=set + Hosts []string `json:"hosts"` + BackendPort intstr.IntOrString `json:"backendPort"` // +optional Path string `json:"path"` @@ -131,6 +133,8 @@ type StackSetExternalIngressSpec struct { type RouteGroupSpec struct { EmbeddedObjectMetaWithAnnotations `json:"metadata,omitempty"` // Hosts is the list of hostnames to add to the routegroup. + // +kubebuilder:validation:MinItems=1 + // +listType=set Hosts []string `json:"hosts"` // AdditionalBackends is the list of additional backends to use for // routing.