Skip to content

Commit

Permalink
fix(gateway): code review
Browse files Browse the repository at this point in the history
Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
  • Loading branch information
Automaat committed Oct 22, 2024
1 parent 57cf529 commit 793a579
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/core/resources/apis/mesh/gateway_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
20 changes: 0 additions & 20 deletions pkg/core/resources/apis/mesh/gateway_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/resources/apis/mesh/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/core/resources/apis/mesh/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 793a579

Please sign in to comment.