Backport of fix(mesh-gateway): remove deregistered service from mesh gateway into release/1.14.x (#15284)

* backport of commit 8083bba320

Co-authored-by: cskh <hui.kang@hashicorp.com>
pull/15286/head
hc-github-team-consul-core 2022-11-07 20:43:39 -05:00 committed by GitHub
parent 8071715461
commit 0f05c4741e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

3
.changelog/15272.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
proxycfg(mesh-gateway): Fix issue where deregistered services are not removed from mesh-gateway clusters.
```

View File

@ -258,6 +258,9 @@ func (s *handlerMeshGateway) handleUpdate(ctx context.Context, u UpdateEvent, sn
// Do those endpoints get cleaned up some other way? // Do those endpoints get cleaned up some other way?
delete(snap.MeshGateway.WatchedServices, sid) delete(snap.MeshGateway.WatchedServices, sid)
cancelFn() cancelFn()
// always remove the sid from the ServiceGroups when un-watch the service
delete(snap.MeshGateway.ServiceGroups, sid)
} }
} }
snap.MeshGateway.WatchedServicesSet = true snap.MeshGateway.WatchedServicesSet = true

View File

@ -482,6 +482,10 @@ func (c *ConfigSnapshot) MeshGatewayValidExportedServices() []structs.ServiceNam
continue // not possible continue // not possible
} }
if _, ok := c.MeshGateway.ServiceGroups[svc]; !ok {
continue // unregistered services
}
chain, ok := c.MeshGateway.DiscoveryChain[svc] chain, ok := c.MeshGateway.DiscoveryChain[svc]
if !ok { if !ok {
continue // ignore; not ready continue // ignore; not ready