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.

pull/20168/head
Dhia Ayachi 2024-01-11 14:45:30 -05:00
parent 50fb45ac74
commit 7b41a61c17
No known key found for this signature in database
2 changed files with 5 additions and 9 deletions

View File

@ -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())
},
}

View File

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