From 7b41a61c175c28bc2a2d676b592721536b089b1a Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Thu, 11 Jan 2024 14:45:30 -0500 Subject: [PATCH] do not init local gateways watch as it's not relevant for remote gateways. do not prevent remote gateway watch from being created when a local one exist as both are different. --- agent/proxycfg/state_test.go | 4 ++-- agent/proxycfg/upstreams.go | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index b962e234ae..43743eb40a 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -1073,8 +1073,8 @@ func TestState_WatchesAndUpdates(t *testing.T) { require.Equal(t, ixnMatch, snap.ConnectProxy.Intentions) require.True(t, snap.ConnectProxy.MeshConfigSet) - // We only watched a single service which is peered - require.Equal(t, 1, snap.ConnectProxy.WatchedLocalGWEndpoints.Len()) + // No event is expected as all services use default or remote mode + require.Equal(t, 0, snap.ConnectProxy.WatchedLocalGWEndpoints.Len()) }, } diff --git a/agent/proxycfg/upstreams.go b/agent/proxycfg/upstreams.go index 332ce8a773..209a3446d9 100644 --- a/agent/proxycfg/upstreams.go +++ b/agent/proxycfg/upstreams.go @@ -363,15 +363,12 @@ func (s *handlerUpstreams) resetWatchesFromChain( continue } } - + if s.source.Datacenter != target.Datacenter || s.proxyID.PartitionOrDefault() != target.Partition { + needGateways[gk.String()] = struct{}{} + } // Register a local gateway watch if any targets are pointing to a peer and require a mode of local. if target.Peer != "" && target.MeshGateway.Mode == structs.MeshGatewayModeLocal { s.setupWatchForLocalGWEndpoints(ctx, snap) - } else { - // If it's not a peering use case, consider watching the gateways for remote targets in wan-fed - if s.source.Datacenter != target.Datacenter || s.proxyID.PartitionOrDefault() != target.Partition { - needGateways[gk.String()] = struct{}{} - } } } @@ -429,7 +426,6 @@ func (s *handlerUpstreams) resetWatchesFromChain( cancel() return err } - snap.WatchedLocalGWEndpoints.InitWatch(gwKey.String(), nil) snap.WatchedGateways[uid][key] = cancel }