From 9d85983d2be5bb4952adda15a49ef306290a35e3 Mon Sep 17 00:00:00 2001 From: Abhipsa20 Date: Thu, 22 Aug 2024 21:12:23 +0530 Subject: [PATCH] added marshalVT to types.resource --- pkg/cache/types/types.go | 1 + pkg/cache/v3/resource.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/cache/types/types.go b/pkg/cache/types/types.go index beb1c1e782..4059c315d0 100644 --- a/pkg/cache/types/types.go +++ b/pkg/cache/types/types.go @@ -9,6 +9,7 @@ import ( // Resource is the base interface for the xDS payload. type Resource interface { proto.Message + MarshalVTStrict() ([]byte, error) } // ResourceWithTTL is a Resource with an optional TTL. diff --git a/pkg/cache/v3/resource.go b/pkg/cache/v3/resource.go index 20a08d32a6..b581db2d9e 100644 --- a/pkg/cache/v3/resource.go +++ b/pkg/cache/v3/resource.go @@ -19,6 +19,7 @@ import ( "encoding/hex" "fmt" "google.golang.org/protobuf/proto" + "reflect" cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3" endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" @@ -125,7 +126,12 @@ func GetResourceWithTTLNames(resources []types.ResourceWithTTL) []string { // MarshalResource converts the Resource to MarshaledResource. func MarshalResource(resource types.Resource) (types.MarshaledResource, error) { - return proto.MarshalOptions{Deterministic: true}.Marshal(resource) + t := reflect.TypeOf(resource) + _, ok := t.MethodByName("MarshalVTStrict") + if !ok { + return proto.MarshalOptions{Deterministic: true}.Marshal(resource) + } + return resource.MarshalVTStrict() } // GetResourceReferences returns a map of dependent resources keyed by resource type, given a map of resources.