Skip to content

Commit

Permalink
feat(ExternalService): validate same value for service and address (#…
Browse files Browse the repository at this point in the history
…8641)

Signed-off-by: Jakub Dyszkiewicz <[email protected]>
  • Loading branch information
jakubdyszkiewicz authored Dec 18, 2023
1 parent ecdbbfc commit 3f3f399
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/core/resources/apis/mesh/external_service_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func (es *ExternalServiceResource) Validate() error {
ExtraTagsValidators: []TagsValidatorFunc{validateProtocol},
}))

if service := es.Spec.GetService(); service != "" {
if host, _, e := net.SplitHostPort(es.Spec.GetNetworking().GetAddress()); e == nil && service == host {
err.AddViolationAt(validators.RootedAt("tags").Key(mesh_proto.ServiceTag), "cannot be the same as networking.address")
}
}

return err.OrNil()
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/core/resources/apis/mesh/external_service_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,19 @@ var _ = Describe("ExternalService", func() {
- field: networking.tls.clientKey
message: data source cannot be empty`,
}),
Entry("kuma.io/service and networking address clash", testCase{
dataplane: `
type: ExternalService
name: es-1
mesh: default
networking:
address: httpbin.org:80
tags:
kuma.io/service: httpbin.org`,
expected: `
violations:
- field: tags["kuma.io/service"]
message: cannot be the same as networking.address`,
}),
)
})

0 comments on commit 3f3f399

Please sign in to comment.