From 8fc736038a3e510c775097fbcee716190f21111c Mon Sep 17 00:00:00 2001 From: Aestek Date: Mon, 20 Jan 2020 14:01:40 +0100 Subject: [PATCH] agent: remove service sidecars in Agent.cleanupRegistration (#7022) Sidecar proxies were left behind when cleaning up after an unsuccessful registration. There are now also removed when the service is cleanup up. --- agent/agent.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agent/agent.go b/agent/agent.go index e4ea4de50b..195c9b2c9d 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2519,6 +2519,9 @@ func (a *Agent) cleanupRegistration(serviceIDs []structs.ServiceID, checksIDs [] if err := a.purgeServiceConfig(s); err != nil { a.logger.Printf("[ERR] consul: service registration: cleanup: failed to purge service config %s file: %s", s, err) } + if err := a.removeServiceSidecars(s, true); err != nil { + a.logger.Printf("[ERR] consul: service registration: cleanup: failed remove sidecars for %s: %s", s, err) + } } for _, c := range checksIDs { @@ -2599,6 +2602,10 @@ func (a *Agent) removeServiceLocked(serviceID structs.ServiceID, persist bool) e a.logger.Printf("[DEBUG] agent: removed service %q", serviceID.String()) // If any Sidecar services exist for the removed service ID, remove them too. + return a.removeServiceSidecars(serviceID, persist) +} + +func (a *Agent) removeServiceSidecars(serviceID structs.ServiceID, persist bool) error { var sidecarSID structs.ServiceID sidecarSID.Init(a.sidecarServiceID(serviceID.ID), &serviceID.EnterpriseMeta) if sidecar := a.State.Service(sidecarSID); sidecar != nil {