diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index c80e57f5d..7e88c6eab 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -1891,8 +1891,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { Nodes: structs.CheckServiceNodes{ { Node: &structs.Node{ - Node: "node1", - Address: "10.0.0.1", + Datacenter: "dc1", + Node: "node1", + Address: "10.0.0.1", }, Service: &structs.NodeService{ Kind: structs.ServiceKindConnectProxy, @@ -1916,8 +1917,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, { Node: &structs.Node{ - Node: "node2", - Address: "10.0.0.2", + Datacenter: "dc1", + Node: "node2", + Address: "10.0.0.2", RaftIndex: structs.RaftIndex{ ModifyIndex: 21, }, @@ -1948,8 +1950,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { structs.CheckServiceNodes{ { Node: &structs.Node{ - Node: "node1", - Address: "10.0.0.1", + Datacenter: "dc1", + Node: "node1", + Address: "10.0.0.1", }, Service: &structs.NodeService{ Kind: structs.ServiceKindConnectProxy, @@ -1973,8 +1976,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, { Node: &structs.Node{ - Node: "node2", - Address: "10.0.0.2", + Datacenter: "dc1", + Node: "node2", + Address: "10.0.0.2", RaftIndex: structs.RaftIndex{ ModifyIndex: 21, }, @@ -2065,8 +2069,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { Nodes: structs.CheckServiceNodes{ { Node: &structs.Node{ - Node: "node2", - Address: "10.0.0.2", + Datacenter: "dc1", + Node: "node2", + Address: "10.0.0.2", RaftIndex: structs.RaftIndex{ ModifyIndex: 21, }, @@ -2099,8 +2104,9 @@ func TestState_WatchesAndUpdates(t *testing.T) { structs.CheckServiceNodes{ { Node: &structs.Node{ - Node: "node2", - Address: "10.0.0.2", + Datacenter: "dc1", + Node: "node2", + Address: "10.0.0.2", RaftIndex: structs.RaftIndex{ ModifyIndex: 21, }, @@ -2144,7 +2150,8 @@ func TestState_WatchesAndUpdates(t *testing.T) { Nodes: structs.CheckServiceNodes{ { Node: &structs.Node{ - Node: "node2", + Datacenter: "dc1", + Node: "node2", }, Service: &structs.NodeService{ Kind: structs.ServiceKindConnectProxy, @@ -2178,7 +2185,8 @@ func TestState_WatchesAndUpdates(t *testing.T) { structs.CheckServiceNodes{ { Node: &structs.Node{ - Node: "node2", + Datacenter: "dc1", + Node: "node2", }, Service: &structs.NodeService{ Kind: structs.ServiceKindConnectProxy, diff --git a/agent/proxycfg/upstreams.go b/agent/proxycfg/upstreams.go index 4cd406a42..e77b554ff 100644 --- a/agent/proxycfg/upstreams.go +++ b/agent/proxycfg/upstreams.go @@ -111,9 +111,8 @@ func (s *handlerUpstreams) handleUpdateUpstreams(ctx context.Context, u cache.Up continue } - // Make sure to use an external address when crossing partitions. - // Datacenter is not considered because transparent proxies cannot dial other datacenters. - isRemote := !structs.EqualPartitions(node.Node.PartitionOrDefault(), s.proxyID.PartitionOrDefault()) + // Make sure to use an external address when crossing partition or DC boundaries. + isRemote := !snap.Locality.Matches(node.Node.Datacenter, node.Node.PartitionOrDefault()) csnIdx, addr, _ := node.BestAddress(isRemote) existing := upstreamsSnapshot.PassthroughIndices[addr]