Consul Connect: Fix validation with multiple local_bind_socket_paths (#22312)

When a consul connect sidecar service is defined with multiple
local_bind_socket_path upstreams, validation would fail due to duplicate
socket address bindings on `:0` being detected.

Validate local_bind_socket_path sockets separately from IP address
sockets.
This commit is contained in:
Ryan R Sundberg
2024-06-04 05:46:24 -07:00
committed by GitHub
parent 13e1a72325
commit 096c72a2f4
2 changed files with 10 additions and 2 deletions

3
.changelog/22312.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
connect: fix validation with multiple socket paths
```

View File

@@ -569,7 +569,7 @@ func groupConnectValidate(g *structs.TaskGroup) error {
}
func groupConnectUpstreamsValidate(g *structs.TaskGroup, services []*structs.Service) error {
listeners := make(map[string]string) // address -> service
listeners := make(map[string]string) // address or path-> service
var connectBlockCount int
var hasTproxy bool
@@ -580,7 +580,12 @@ func groupConnectUpstreamsValidate(g *structs.TaskGroup, services []*structs.Ser
}
if service.Connect.HasSidecar() && service.Connect.SidecarService.Proxy != nil {
for _, up := range service.Connect.SidecarService.Proxy.Upstreams {
listener := net.JoinHostPort(up.LocalBindAddress, strconv.Itoa(up.LocalBindPort))
var listener string
if up.LocalBindSocketPath == "" {
listener = net.JoinHostPort(up.LocalBindAddress, strconv.Itoa(up.LocalBindPort))
} else {
listener = up.LocalBindSocketPath
}
if s, exists := listeners[listener]; exists {
return fmt.Errorf(
"Consul Connect services %q and %q in group %q using same address for upstreams (%s)",