From 89748d805a49d9928351b871460a0c6a8b34a12a Mon Sep 17 00:00:00 2001 From: Freddy Date: Thu, 17 Jun 2021 13:50:54 -0600 Subject: [PATCH] Merge pull request #10423 from hashicorp/fix-map --- .changelog/10423.txt | 3 +++ agent/proxycfg/state.go | 15 +++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 .changelog/10423.txt diff --git a/.changelog/10423.txt b/.changelog/10423.txt new file mode 100644 index 0000000000..6a47f10a7e --- /dev/null +++ b/.changelog/10423.txt @@ -0,0 +1,3 @@ +```release-note:bug +proxycfg: avoid panic when transparent proxy upstream is added and then removed. +``` diff --git a/agent/proxycfg/state.go b/agent/proxycfg/state.go index 64bfc424e3..2d5e2b61cf 100644 --- a/agent/proxycfg/state.go +++ b/agent/proxycfg/state.go @@ -827,8 +827,7 @@ func (s *state) handleUpdateConnectProxy(u cache.UpdateEvent, snap *ConfigSnapsh // Clean up data from services that were not in the update for sn := range snap.ConnectProxy.WatchedUpstreams { - upstream := snap.ConnectProxy.UpstreamConfig[sn] - if upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { + if upstream, ok := snap.ConnectProxy.UpstreamConfig[sn]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { continue } if _, ok := seenServices[sn]; !ok { @@ -836,8 +835,7 @@ func (s *state) handleUpdateConnectProxy(u cache.UpdateEvent, snap *ConfigSnapsh } } for sn := range snap.ConnectProxy.WatchedUpstreamEndpoints { - upstream := snap.ConnectProxy.UpstreamConfig[sn] - if upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { + if upstream, ok := snap.ConnectProxy.UpstreamConfig[sn]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { continue } if _, ok := seenServices[sn]; !ok { @@ -845,8 +843,7 @@ func (s *state) handleUpdateConnectProxy(u cache.UpdateEvent, snap *ConfigSnapsh } } for sn := range snap.ConnectProxy.WatchedGateways { - upstream := snap.ConnectProxy.UpstreamConfig[sn] - if upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { + if upstream, ok := snap.ConnectProxy.UpstreamConfig[sn]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { continue } if _, ok := seenServices[sn]; !ok { @@ -854,8 +851,7 @@ func (s *state) handleUpdateConnectProxy(u cache.UpdateEvent, snap *ConfigSnapsh } } for sn := range snap.ConnectProxy.WatchedGatewayEndpoints { - upstream := snap.ConnectProxy.UpstreamConfig[sn] - if upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { + if upstream, ok := snap.ConnectProxy.UpstreamConfig[sn]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { continue } if _, ok := seenServices[sn]; !ok { @@ -863,8 +859,7 @@ func (s *state) handleUpdateConnectProxy(u cache.UpdateEvent, snap *ConfigSnapsh } } for sn, cancelFn := range snap.ConnectProxy.WatchedDiscoveryChains { - upstream := snap.ConnectProxy.UpstreamConfig[sn] - if upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { + if upstream, ok := snap.ConnectProxy.UpstreamConfig[sn]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter { continue } if _, ok := seenServices[sn]; !ok {