xds/clients: pass context.Context and extensible structs to Decoder and ResourceWatcher
Author: dashpoleCreated Sep 30, 2026Updated Sep 30, 2026
Use case(s) - what problem will this feature solve?
In internal/xds/clients/xdsclient:
- Neither
Decoder.Decode(resource *AnyProto, opts DecodeOptions) (*DecodeResult, error)norResourceWatchercallbacks (ResourceChanged,ResourceError,AmbientError) accept acontext.Context—even thoughauthority.goinvokes watcher callbacks viawatcherCallbackSerializer.TrySchedule(func(context.Context) { ... })and currently discards thecontext.Contextparameter. Consumers recording metrics, events, or context-awaresloglogs insideDecodeorResourceWatchercallbacks have nocontext.Contextavailable. DecodeOptionsexposes the entire*Configpointer (allowing decoders to mutate the client'sConfigmap fields), whereasResourceWatcher.ResourceChanged(data ResourceData, done func())takesResourceDatadirectly with no way to pass resource metadata (such as the resource name or version) without breaking the interface signature in the future.
Proposed Solution
- Pass
ctx context.Contextas the first parameter toDecoder.DecodeandResourceWatchermethods:Decode(ctx context.Context, resource AnyProto, opts DecodeOptions) (*DecodeResult, error)ResourceChanged(ctx context.Context, update ResourceUpdate, done func())ResourceError(ctx context.Context, err error, done func())AmbientError(ctx context.Context, err error, done func())
- Pass an extensible
ResourceUpdatestruct (type ResourceUpdate struct { Name string; Data ResourceData; Version string }) toResourceChangedso future fields can be added backwards-compatibly. - Narrow
DecodeOptionsto expose only the read-only server/authority context needed by decoders rather than mutable*Config.
Alternatives Considered
Keeping the existing signatures without context.Context or ResourceUpdate. Changing these interface signatures after xdsclient is exported publicly would be a breaking v1 API change.
Additional Context
Part of #9455.
Source: grpc/grpc-go