Ensure we remove Connect proxy before deregistering the service itself (#5482)

This will fix https://github.com/hashicorp/consul/issues/5351
This commit is contained in:
Pierre Souchay 2019-03-15 21:14:46 +01:00 committed by Paul Banks
parent a73d983d19
commit 8f0fe5a00a

View file

@ -2075,6 +2075,17 @@ func (a *Agent) removeServiceLocked(serviceID string, persist bool) error {
checkIDs = append(checkIDs, id) checkIDs = append(checkIDs, id)
} }
// Remove the associated managed proxy if it exists
// This has to be DONE before purging configuration as might might have issues
// With ACLs otherwise
for proxyID, p := range a.State.Proxies() {
if p.Proxy.TargetServiceID == serviceID {
if err := a.removeProxyLocked(proxyID, true); err != nil {
return err
}
}
}
// Remove service immediately // Remove service immediately
if err := a.State.RemoveServiceWithChecks(serviceID, checkIDs); err != nil { if err := a.State.RemoveServiceWithChecks(serviceID, checkIDs); err != nil {
a.logger.Printf("[WARN] agent: Failed to deregister service %q: %s", serviceID, err) a.logger.Printf("[WARN] agent: Failed to deregister service %q: %s", serviceID, err)
@ -2098,15 +2109,6 @@ func (a *Agent) removeServiceLocked(serviceID string, persist bool) error {
} }
} }
// Remove the associated managed proxy if it exists
for proxyID, p := range a.State.Proxies() {
if p.Proxy.TargetServiceID == serviceID {
if err := a.removeProxyLocked(proxyID, true); err != nil {
return err
}
}
}
a.logger.Printf("[DEBUG] agent: removed service %q", serviceID) a.logger.Printf("[DEBUG] agent: removed service %q", serviceID)
// If any Sidecar services exist for the removed service ID, remove them too. // If any Sidecar services exist for the removed service ID, remove them too.