Skip to content

Commit d307d75

Browse files
easwarsPranjali-2501
authored andcommitted
xdsclient: preserve original bytes for decoding when the resource is wrapped (#8411)
1 parent b34f845 commit d307d75

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

xds/internal/clients/xdsclient/channel.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,17 @@ func decodeResponse(opts *DecodeOptions, rType *ResourceType, resp response) (ma
253253
perResourceErrors := make(map[string]error) // Tracks resource validation errors, where we have a resource name.
254254
ret := make(map[string]dataAndErrTuple) // Return result, a map from resource name to either resource data or error.
255255
for _, r := range resp.resources {
256-
r, err := xdsresource.UnwrapResource(r)
256+
// Unwrap and validate the resource, but preserve the original bytes for
257+
// decoding. This is required for resource types that don't have a name
258+
// field in the resource itself, but only have one in the wrapped
259+
// resource.
260+
inner, err := xdsresource.UnwrapResource(r)
257261
if err != nil {
258262
topLevelErrors = append(topLevelErrors, err)
259263
continue
260264
}
261-
if _, ok := opts.Config.ResourceTypes[r.TypeUrl]; !ok || r.TypeUrl != resp.typeURL {
262-
topLevelErrors = append(topLevelErrors, xdsresource.NewErrorf(xdsresource.ErrorTypeResourceTypeUnsupported, "unexpected resource type: %q ", r.GetTypeUrl()))
265+
if _, ok := opts.Config.ResourceTypes[inner.GetTypeUrl()]; !ok || inner.GetTypeUrl() != resp.typeURL {
266+
topLevelErrors = append(topLevelErrors, xdsresource.NewErrorf(xdsresource.ErrorTypeResourceTypeUnsupported, "unexpected resource type: %q ", inner.GetTypeUrl()))
263267
continue
264268
}
265269
result, err := rType.Decoder.Decode(r.GetValue(), *opts)

0 commit comments

Comments
 (0)