diff --git a/internal/xds/cache/snapshotcache.go b/internal/xds/cache/snapshotcache.go index 61b923f22c..6c989b37e4 100644 --- a/internal/xds/cache/snapshotcache.go +++ b/internal/xds/cache/snapshotcache.go @@ -90,7 +90,13 @@ func (s *snapshotCache) GenerateNewSnapshot(irKey string, resources types.XdsRes } xdsSnapshotCreateTotal.WithSuccess().Increment() - s.lastSnapshot[irKey] = snapshot + // Delete snapshot from cache if resources are nil + if resources == nil { + delete(s.lastSnapshot, irKey) + } else { + // Update snapshot in cache + s.lastSnapshot[irKey] = snapshot + } for _, node := range s.getNodeIDs(irKey) { s.log.Debugf("Generating a snapshot with Node %s", node) diff --git a/internal/xds/runner/runner_test.go b/internal/xds/runner/runner_test.go index 154edbdb8c..bb666ead0f 100644 --- a/internal/xds/runner/runner_test.go +++ b/internal/xds/runner/runner_test.go @@ -318,7 +318,7 @@ func TestRunner(t *testing.T) { xdsIR.Delete("test") require.Eventually(t, func() bool { // Wait for the IR to be empty after deletion - return len(xdsIR.LoadAll()) == 0 + return !r.cache.SnapshotHasIrKey("test") && len(xdsIR.LoadAll()) == 0 }, time.Second*5, time.Millisecond*50) }