mirror of https://github.com/hashicorp/consul
Simplify mgw watch mgmt
parent
d54db25421
commit
5f97223822
|
@ -534,9 +534,11 @@ func (s *handlerMeshGateway) handleUpdate(ctx context.Context, u UpdateEvent, sn
|
||||||
snap.MeshGateway.MeshConfig = meshConf
|
snap.MeshGateway.MeshConfig = meshConf
|
||||||
snap.MeshGateway.MeshConfigSet = true
|
snap.MeshGateway.MeshConfigSet = true
|
||||||
|
|
||||||
|
// If we're peering through mesh gateways it means the config entry may be deleted
|
||||||
|
// or the flag was disabled. Here we clean up related watches if they exist.
|
||||||
if !meshConf.PeerThroughMeshGateways() {
|
if !meshConf.PeerThroughMeshGateways() {
|
||||||
// We avoid canceling server watches when WAN federation is enabled since it
|
// We avoid canceling server watches when WAN federation is enabled since it
|
||||||
// always requires server watches.
|
// always requires a watch to the local servers.
|
||||||
if s.meta[structs.MetaWANFederationKey] != "1" {
|
if s.meta[structs.MetaWANFederationKey] != "1" {
|
||||||
// If the entry was deleted we cancel watches that may have existed because of
|
// If the entry was deleted we cancel watches that may have existed because of
|
||||||
// PeerThroughMeshGateways being set in the past.
|
// PeerThroughMeshGateways being set in the past.
|
||||||
|
@ -556,8 +558,7 @@ func (s *handlerMeshGateway) handleUpdate(ctx context.Context, u UpdateEvent, sn
|
||||||
// we need to start watching the list of peering connections in all partitions
|
// we need to start watching the list of peering connections in all partitions
|
||||||
// to set up outbound routes for the control plane. Consul servers are in the default partition,
|
// to set up outbound routes for the control plane. Consul servers are in the default partition,
|
||||||
// so only mesh gateways here have his responsibility.
|
// so only mesh gateways here have his responsibility.
|
||||||
if meshConf.PeerThroughMeshGateways() &&
|
if snap.ProxyID.InDefaultPartition() &&
|
||||||
snap.ProxyID.InDefaultPartition() &&
|
|
||||||
snap.MeshGateway.PeerServersWatchCancel == nil {
|
snap.MeshGateway.PeerServersWatchCancel == nil {
|
||||||
|
|
||||||
peeringListCtx, cancel := context.WithCancel(ctx)
|
peeringListCtx, cancel := context.WithCancel(ctx)
|
||||||
|
@ -575,18 +576,12 @@ func (s *handlerMeshGateway) handleUpdate(ctx context.Context, u UpdateEvent, sn
|
||||||
snap.MeshGateway.PeerServersWatchCancel = cancel
|
snap.MeshGateway.PeerServersWatchCancel = cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
snap.MeshGateway.MeshConfigSet = true
|
// We avoid initializing Consul server watches when WAN federation is enabled since it
|
||||||
|
|
||||||
// We avoid managing Consul server watches when WAN federation is enabled since it
|
|
||||||
// always requires server watches.
|
// always requires server watches.
|
||||||
if s.meta[structs.MetaWANFederationKey] == "1" {
|
if s.meta[structs.MetaWANFederationKey] == "1" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !meshConf.PeerThroughMeshGateways() {
|
|
||||||
snap.MeshGateway.WatchedLocalServers.CancelWatch(structs.ConsulServiceName)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if snap.MeshGateway.WatchedLocalServers.IsWatched(structs.ConsulServiceName) {
|
if snap.MeshGateway.WatchedLocalServers.IsWatched(structs.ConsulServiceName) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue