From 5f4d7dfa65fba1805c844e905c84615fca555a5c Mon Sep 17 00:00:00 2001 From: Valerian Roche Date: Tue, 19 Apr 2022 16:46:54 -0400 Subject: [PATCH] Support specific case of specific subscription removed while in wildcard mode Signed-off-by: Valerian Roche --- pkg/cache/v3/delta.go | 1 + pkg/server/delta/v3/server.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/cache/v3/delta.go b/pkg/cache/v3/delta.go index c74281b30e..deaeeb7ed1 100644 --- a/pkg/cache/v3/delta.go +++ b/pkg/cache/v3/delta.go @@ -53,6 +53,7 @@ func createDeltaResponse(ctx context.Context, req *DeltaRequest, state stream.St } // Compute resources for removal + // The resource version can be set to "" here to trigger a removal even if never returned before for name := range state.GetResourceVersions() { if _, ok := resources.resourceMap[name]; !ok { toRemove = append(toRemove, name) diff --git a/pkg/server/delta/v3/server.go b/pkg/server/delta/v3/server.go index 17c46aeb85..120c472468 100644 --- a/pkg/server/delta/v3/server.go +++ b/pkg/server/delta/v3/server.go @@ -235,5 +235,13 @@ func (s *server) unsubscribe(resources []string, streamState *stream.StreamState continue } delete(sv, resource) + if _, ok := sv[resource]; ok && streamState.IsWildcard() { + // xds protocol specifically states that if a resource if unsubscribed while a wildcard watch is present, + // the control-plane must return a response with either the resource set as removed (if no longer present in the snapshot) + // or with its content + // If the stream is in wildcard mode specifying an empty entry in the resource versions will either send the resource content + // or mark it as removed (done in createDeltaResponse) + state.GetResourceVersions()[resource] = "" + } } }