From 458eb41be1390ae53987477ee9355dd316e02e24 Mon Sep 17 00:00:00 2001 From: freddygv Date: Fri, 19 Mar 2021 19:57:23 -0600 Subject: [PATCH] Prevent synthetic upstreams without addresses from failing duplicate ip/port validation --- agent/structs/structs.go | 4 +++- agent/structs/structs_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/agent/structs/structs.go b/agent/structs/structs.go index 91dfd0b4bc..9c8dee49fb 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -1189,7 +1189,9 @@ func (s *NodeService) Validate() error { } addr = net.JoinHostPort(addr, fmt.Sprintf("%d", u.LocalBindPort)) - if _, ok := bindAddrs[addr]; ok { + // Centrally configured upstreams will fail this check if there are multiple because they do not have an address/port. + // Only consider non-centrally configured upstreams in this check since those are the ones we create listeners for. + if _, ok := bindAddrs[addr]; ok && !u.CentrallyConfigured { result = multierror.Append(result, fmt.Errorf( "upstreams cannot contain duplicates by local bind address and port; %q is specified twice", addr)) continue diff --git a/agent/structs/structs_test.go b/agent/structs/structs_test.go index f6a6f5dddb..05b75f07ea 100644 --- a/agent/structs/structs_test.go +++ b/agent/structs/structs_test.go @@ -768,6 +768,24 @@ func TestStructs_NodeService_ValidateConnectProxy(t *testing.T) { }, "upstreams cannot contain duplicates", }, + { + "connect-proxy: Centrally configured upstreams can have duplicate ip/port", + func(x *NodeService) { + x.Proxy.Upstreams = Upstreams{ + { + DestinationType: UpstreamDestTypeService, + DestinationName: "foo", + CentrallyConfigured: true, + }, + { + DestinationType: UpstreamDestTypeService, + DestinationName: "bar", + CentrallyConfigured: true, + }, + } + }, + "", + }, { "connect-proxy: Upstreams duplicated by ip and port", func(x *NodeService) {