From 57cf5294725ac9959ec323e6d1319a4f0acc1d4e Mon Sep 17 00:00:00 2001 From: Marcin Skalski Date: Mon, 21 Oct 2024 14:01:23 +0200 Subject: [PATCH] fix(gateway): MeshGateway tags validation consistent with MeshRoute tags validation Signed-off-by: Marcin Skalski --- .../resources/apis/mesh/gateway_validator.go | 2 +- .../apis/mesh/gateway_validator_test.go | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/core/resources/apis/mesh/gateway_validator.go b/pkg/core/resources/apis/mesh/gateway_validator.go index 7c94491b8671..72e0b7e8761e 100644 --- a/pkg/core/resources/apis/mesh/gateway_validator.go +++ b/pkg/core/resources/apis/mesh/gateway_validator.go @@ -26,7 +26,7 @@ func (g *MeshGatewayResource) Validate() error { // The top-level selector is used to bind the gateway to a set // of dataplanes, so the service tag must not be used here. - err.Add(ValidateSelector( + err.Add(ValidateTags( validators.RootedAt("tags"), g.Spec.GetTags(), ValidateTagsOpts{ diff --git a/pkg/core/resources/apis/mesh/gateway_validator_test.go b/pkg/core/resources/apis/mesh/gateway_validator_test.go index 96352d2c1fea..c18d6d78a12a 100644 --- a/pkg/core/resources/apis/mesh/gateway_validator_test.go +++ b/pkg/core/resources/apis/mesh/gateway_validator_test.go @@ -166,6 +166,26 @@ conf: tags: name: https `), + ErrorCase("has tag with invalid characters", + validators.Violation{ + Field: `tags["port"]`, + Message: `tag value must consist of alphanumeric characters, dots, dashes and underscores`, + }, ` +type: MeshGateway +name: gateway +mesh: default +selectors: + - match: + kuma.io/service: gateway +tags: + port: http/443 +conf: + listeners: + - port: 443 + protocol: HTTP + tags: + name: https +`), ErrorCase("doesn't have a configuration spec", validators.Violation{