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.
This commit is contained in:
Aestek 2020-01-20 14:01:40 +01:00 committed by Hans Hasselberg
parent 9c1361c02b
commit 8fc736038a
1 changed files with 7 additions and 0 deletions

View File

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