Account for upstream targets in another DC.

Transparent proxies typically cannot dial upstreams in remote
datacenters. However, if their upstream configures a redirect to a
remote DC then the upstream targets will be in another datacenter.

In that sort of case we should use the WAN address for the passthrough.
This commit is contained in:
freddygv 2022-02-09 17:16:00 -07:00
parent 7fba7456ec
commit 8eaca35df1
2 changed files with 24 additions and 17 deletions

View File

@ -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,

View File

@ -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]