diff --git a/apis/v1/grpcroute_types.go b/apis/v1/grpcroute_types.go index 5bfc4a4d91..6e496e8033 100644 --- a/apis/v1/grpcroute_types.go +++ b/apis/v1/grpcroute_types.go @@ -143,7 +143,7 @@ type GRPCRouteSpec struct { // // +optional // +kubebuilder:validation:MaxItems=16 - // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" + // +kubebuilder:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" Rules []GRPCRouteRule `json:"rules,omitempty"` } diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index cf01deb5b9..611c348ca6 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -117,7 +117,7 @@ type HTTPRouteSpec struct { // Rules are a list of HTTP matchers, filters and actions. // // +optional - // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" + // +kubebuilder:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" // +kubebuilder:validation:MaxItems=16 // +kubebuilder:default={{matches: {{path: {type: "PathPrefix", value: "/"}}}}} Rules []HTTPRouteRule `json:"rules,omitempty"` diff --git a/apis/v1alpha2/tcproute_types.go b/apis/v1alpha2/tcproute_types.go index 3178558623..65231a8285 100644 --- a/apis/v1alpha2/tcproute_types.go +++ b/apis/v1alpha2/tcproute_types.go @@ -49,7 +49,7 @@ type TCPRouteSpec struct { // // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=16 - // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" + // +kubebuilder:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" Rules []TCPRouteRule `json:"rules"` } diff --git a/apis/v1alpha2/tlsroute_types.go b/apis/v1alpha2/tlsroute_types.go index d6d2b25e73..bce70a74b7 100644 --- a/apis/v1alpha2/tlsroute_types.go +++ b/apis/v1alpha2/tlsroute_types.go @@ -90,7 +90,7 @@ type TLSRouteSpec struct { // // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=16 - // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" + // +kubebuilder:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" Rules []TLSRouteRule `json:"rules"` } diff --git a/apis/v1alpha2/udproute_types.go b/apis/v1alpha2/udproute_types.go index 05ac7a20ac..b05f5503c7 100644 --- a/apis/v1alpha2/udproute_types.go +++ b/apis/v1alpha2/udproute_types.go @@ -49,7 +49,7 @@ type UDPRouteSpec struct { // // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=16 - // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" + // +kubebuilder:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))" Rules []UDPRouteRule `json:"rules"` } diff --git a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml index 6cd6a741fd..f3b70090a6 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml @@ -2041,7 +2041,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object @@ -4382,7 +4382,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 1dc0acbf7b..f8c14041ff 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -2939,7 +2939,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object @@ -6184,7 +6184,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object diff --git a/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml index a0db2b6541..8b27455fd7 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml @@ -501,7 +501,7 @@ spec: minItems: 1 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) required: diff --git a/config/crd/experimental/gateway.networking.k8s.io_tlsroutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_tlsroutes.yaml index 69266d4858..3327952868 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_tlsroutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_tlsroutes.yaml @@ -574,7 +574,7 @@ spec: minItems: 1 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) required: diff --git a/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml index ad23d65661..34e7ea595d 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml @@ -501,7 +501,7 @@ spec: minItems: 1 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) required: diff --git a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml index 969780ddc3..c1221879d0 100644 --- a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml @@ -1912,7 +1912,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object @@ -4109,7 +4109,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object diff --git a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml index 4d3e4d9ef0..afe6b2a7d7 100644 --- a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml @@ -2739,7 +2739,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object @@ -5769,7 +5769,7 @@ spec: maxItems: 16 type: array x-kubernetes-validations: - - message: Route name must be unique within the route + - message: Rule name must be unique within the route rule: self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name)) type: object diff --git a/pkg/test/cel/httproute_test.go b/pkg/test/cel/httproute_test.go index c8e82d735c..407fc73f44 100644 --- a/pkg/test/cel/httproute_test.go +++ b/pkg/test/cel/httproute_test.go @@ -1211,7 +1211,7 @@ func TestHTTPRouteRule(t *testing.T) { }, { name: "invalid because multiple names are repeated", - wantErrors: []string{"Route name must be unique within the route"}, + wantErrors: []string{"Rule name must be unique within the route"}, rules: []gatewayv1.HTTPRouteRule{ { Name: ptrTo(gatewayv1.SectionName("name1")), @@ -1221,6 +1221,17 @@ func TestHTTPRouteRule(t *testing.T) { }, }, }, + { + name: "valid because names are unique", + wantErrors: nil, + rules: []gatewayv1.HTTPRouteRule{ + // Ok to have multiple nil + {Name: nil}, + {Name: nil}, + {Name: ptrTo(gatewayv1.SectionName("name1"))}, + {Name: ptrTo(gatewayv1.SectionName("name2"))}, + }, + }, } for _, tc := range tests {