From 793a5795cc93adc910fd9bcbe36d0080a301125d Mon Sep 17 00:00:00 2001 From: Marcin Skalski Date: Tue, 22 Oct 2024 17:35:54 +0200 Subject: [PATCH] fix(gateway): code review Signed-off-by: Marcin Skalski --- .../resources/apis/mesh/gateway_validator.go | 2 +- .../apis/mesh/gateway_validator_test.go | 20 ------------------- pkg/core/resources/apis/mesh/validators.go | 2 +- .../resources/apis/mesh/validators_test.go | 14 +++++++++++++ 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/pkg/core/resources/apis/mesh/gateway_validator.go b/pkg/core/resources/apis/mesh/gateway_validator.go index 72e0b7e8761e..7c94491b8671 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(ValidateTags( + err.Add(ValidateSelector( 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 c18d6d78a12a..96352d2c1fea 100644 --- a/pkg/core/resources/apis/mesh/gateway_validator_test.go +++ b/pkg/core/resources/apis/mesh/gateway_validator_test.go @@ -166,26 +166,6 @@ 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{ diff --git a/pkg/core/resources/apis/mesh/validators.go b/pkg/core/resources/apis/mesh/validators.go index 7e5729a87cdf..72b1d0d0750e 100644 --- a/pkg/core/resources/apis/mesh/validators.go +++ b/pkg/core/resources/apis/mesh/validators.go @@ -402,7 +402,7 @@ func ValidateTargetRef( err.Add(validateName(ref.Name, opts.AllowedInvalidNames)) err.Add(disallowedField("mesh", ref.Mesh, ref.Kind)) err.Add(disallowedField("proxyTypes", ref.ProxyTypes, ref.Kind)) - err.Add(ValidateTags(validators.RootedAt("tags"), ref.Tags, ValidateTagsOpts{})) + err.Add(ValidateSelector(validators.RootedAt("tags"), ref.Tags, ValidateTagsOpts{})) if ref.Kind == common_api.MeshGateway && len(ref.Tags) > 0 && !opts.GatewayListenerTagsAllowed { err.Add(disallowedField("tags", ref.Tags, ref.Kind)) } diff --git a/pkg/core/resources/apis/mesh/validators_test.go b/pkg/core/resources/apis/mesh/validators_test.go index bdf76f0f2232..79768e24feca 100644 --- a/pkg/core/resources/apis/mesh/validators_test.go +++ b/pkg/core/resources/apis/mesh/validators_test.go @@ -189,6 +189,20 @@ name: gateway.namespace }, }, }), + Entry("MeshGateway with slash in tags", testCase{ + inputYaml: ` +kind: MeshGateway +name: gateway.namespace +tags: + port: http/443 +`, + opts: &ValidateTargetRefOpts{ + SupportedKinds: []common_api.TargetRefKind{ + common_api.MeshGateway, + }, + GatewayListenerTagsAllowed: true, + }, + }), Entry("MeshHTTPRoute", testCase{ inputYaml: ` kind: MeshHTTPRoute