Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kuma-cp) Clear snapshots from cache on disconnect #2172

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/sds/server/v3/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ func (d *DataplaneReconciler) Reconcile(proxyId *core_xds.ProxyId) error {
}

func (d *DataplaneReconciler) Cleanup(proxyId *core_xds.ProxyId) error {
if err := d.cache.SetSnapshot(proxyId.String(), envoy_cache.Snapshot{}); err != nil {
return err
}
d.cache.ClearSnapshot(proxyId.String())
d.Lock()
delete(d.proxySnapshotInfo, proxyId.String())
d.Unlock()
Expand Down
6 changes: 2 additions & 4 deletions pkg/xds/server/v3/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ type reconciler struct {
}

func (r *reconciler) Clear(proxyId *model.ProxyId) error {
// cache.Clear() operation does not push a new (empty) configuration to Envoy.
// That is why instead of calling cache.Clear() we set configuration to an empty Snapshot.
// This fake value will be removed from cache on Envoy disconnect.
return r.cacher.Cache(&envoy_core.Node{Id: proxyId.String()}, envoy_cache.Snapshot{})
r.cacher.Clear(&envoy_core.Node{Id: proxyId.String()})
return nil
}

func (r *reconciler) Reconcile(ctx xds_context.Context, proxy *model.Proxy) error {
Expand Down
16 changes: 16 additions & 0 deletions pkg/xds/server/v3/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ var _ = Describe("Reconcile", func() {
Expect(snapshot.Resources[envoy_types.Cluster].Version).To(Equal("v8"))
Expect(snapshot.Resources[envoy_types.Endpoint].Version).To(Equal("v9"))
Expect(snapshot.Resources[envoy_types.Secret].Version).To(Equal("v10"))

By("simulating clear")
// when
err = r.Clear(&proxy.Id)
Expect(err).ToNot(HaveOccurred())
snapshot, err = xdsContext.Cache().GetSnapshot("demo.example")

// then
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("no snapshot found"))

Expect(snapshot.Resources[envoy_types.Listener].Version).To(Equal(""))
Expect(snapshot.Resources[envoy_types.Route].Version).To(Equal(""))
Expect(snapshot.Resources[envoy_types.Cluster].Version).To(Equal(""))
Expect(snapshot.Resources[envoy_types.Endpoint].Version).To(Equal(""))
Expect(snapshot.Resources[envoy_types.Secret].Version).To(Equal(""))
})
})
})
Expand Down