mirror of https://github.com/grpc/grpc-go.git
xdsclient: preserve original bytes for decoding when the resource is wrapped (#8411)
This commit is contained in:
parent
b34f845d70
commit
d307d7590a
|
|
@ -253,13 +253,17 @@ func decodeResponse(opts *DecodeOptions, rType *ResourceType, resp response) (ma
|
||||||
perResourceErrors := make(map[string]error) // Tracks resource validation errors, where we have a resource name.
|
perResourceErrors := make(map[string]error) // Tracks resource validation errors, where we have a resource name.
|
||||||
ret := make(map[string]dataAndErrTuple) // Return result, a map from resource name to either resource data or error.
|
ret := make(map[string]dataAndErrTuple) // Return result, a map from resource name to either resource data or error.
|
||||||
for _, r := range resp.resources {
|
for _, r := range resp.resources {
|
||||||
r, err := xdsresource.UnwrapResource(r)
|
// Unwrap and validate the resource, but preserve the original bytes for
|
||||||
|
// decoding. This is required for resource types that don't have a name
|
||||||
|
// field in the resource itself, but only have one in the wrapped
|
||||||
|
// resource.
|
||||||
|
inner, err := xdsresource.UnwrapResource(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
topLevelErrors = append(topLevelErrors, err)
|
topLevelErrors = append(topLevelErrors, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := opts.Config.ResourceTypes[r.TypeUrl]; !ok || r.TypeUrl != resp.typeURL {
|
if _, ok := opts.Config.ResourceTypes[inner.GetTypeUrl()]; !ok || inner.GetTypeUrl() != resp.typeURL {
|
||||||
topLevelErrors = append(topLevelErrors, xdsresource.NewErrorf(xdsresource.ErrorTypeResourceTypeUnsupported, "unexpected resource type: %q ", r.GetTypeUrl()))
|
topLevelErrors = append(topLevelErrors, xdsresource.NewErrorf(xdsresource.ErrorTypeResourceTypeUnsupported, "unexpected resource type: %q ", inner.GetTypeUrl()))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result, err := rType.Decoder.Decode(r.GetValue(), *opts)
|
result, err := rType.Decoder.Decode(r.GetValue(), *opts)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue