mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 04:37:31 +08:00
upgrade to istio 1.19 (#1211)
Co-authored-by: CH3CHO <ch3cho@qq.com> Co-authored-by: rinfx <893383980@qq.com>
This commit is contained in:
@@ -17,111 +17,177 @@ package mcp
|
||||
// nolint
|
||||
import (
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
|
||||
"github.com/gogo/protobuf/types"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/golang/protobuf/ptypes/any"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
mcp "istio.io/api/mcp/v1alpha1"
|
||||
"istio.io/istio/pilot/pkg/model"
|
||||
"istio.io/istio/pilot/pkg/xds"
|
||||
cfg "istio.io/istio/pkg/config"
|
||||
"istio.io/istio/pkg/config/schema/gvk"
|
||||
)
|
||||
|
||||
var (
|
||||
_ model.XdsResourceGenerator = ServiceEntryGenerator{}
|
||||
_ model.XdsDeltaResourceGenerator = ServiceEntryGenerator{}
|
||||
)
|
||||
|
||||
type GeneratorOptions struct {
|
||||
KeepConfigLabels bool
|
||||
KeepConfigAnnotations bool
|
||||
}
|
||||
|
||||
type ServiceEntryGenerator struct {
|
||||
Server *xds.DiscoveryServer
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c ServiceEntryGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
return generate(proxy, push.AllServiceEntries, w, updates)
|
||||
func (c ServiceEntryGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
serviceEntries := c.Environment.List(gvk.ServiceEntry, model.NamespaceAll)
|
||||
if serviceEntries != nil {
|
||||
// To ensure the ip allocation logic deterministically
|
||||
// allocates the same IP to a service entry.
|
||||
sort.Slice(serviceEntries, func(i, j int) bool {
|
||||
// If creation time is the same, then behavior is nondeterministic. In this case, we can
|
||||
// pick an arbitrary but consistent ordering based on name and namespace, which is unique.
|
||||
// CreationTimestamp is stored in seconds, so this is not uncommon.
|
||||
if serviceEntries[i].CreationTimestamp == serviceEntries[j].CreationTimestamp {
|
||||
in := serviceEntries[i].Name + "." + serviceEntries[i].Namespace
|
||||
jn := serviceEntries[j].Name + "." + serviceEntries[j].Namespace
|
||||
return in < jn
|
||||
}
|
||||
return serviceEntries[i].CreationTimestamp.Before(serviceEntries[j].CreationTimestamp)
|
||||
})
|
||||
}
|
||||
return generate(proxy, serviceEntries, w, updates, false, false)
|
||||
}
|
||||
|
||||
func (c ServiceEntryGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) ([]*any.Any, []string, model.XdsLogDetails, bool, error) {
|
||||
func (c ServiceEntryGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
type VirtualServiceGenerator struct {
|
||||
Server *xds.DiscoveryServer
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c VirtualServiceGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
return generate(proxy, push.AllVirtualServices, w, updates)
|
||||
func (c VirtualServiceGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
virtualServices := c.Environment.List(gvk.VirtualService, model.NamespaceAll)
|
||||
return generate(proxy, virtualServices, w, updates, false, false)
|
||||
}
|
||||
|
||||
func (c VirtualServiceGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) ([]*any.Any, []string, model.XdsLogDetails, bool, error) {
|
||||
func (c VirtualServiceGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
type DestinationRuleGenerator struct {
|
||||
Server *xds.DiscoveryServer
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c DestinationRuleGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
return generate(proxy, push.AllDestinationRules, w, updates)
|
||||
func (c DestinationRuleGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
rules := c.Environment.List(gvk.DestinationRule, model.NamespaceAll)
|
||||
return generate(proxy, rules, w, updates, false, false)
|
||||
}
|
||||
|
||||
func (c DestinationRuleGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) ([]*any.Any, []string, model.XdsLogDetails, bool, error) {
|
||||
func (c DestinationRuleGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
type EnvoyFilterGenerator struct {
|
||||
Server *xds.DiscoveryServer
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c EnvoyFilterGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
return generate(proxy, push.AllEnvoyFilters, w, updates)
|
||||
func (c EnvoyFilterGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
filters := c.Environment.List(gvk.EnvoyFilter, model.NamespaceAll)
|
||||
return generate(proxy, filters, w, updates, false, false)
|
||||
}
|
||||
|
||||
func (c EnvoyFilterGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) ([]*any.Any, []string, model.XdsLogDetails, bool, error) {
|
||||
func (c EnvoyFilterGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
type GatewayGenerator struct {
|
||||
Server *xds.DiscoveryServer
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c GatewayGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
return generate(proxy, push.AllGateways, w, updates)
|
||||
func (c GatewayGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
gateways := c.Environment.List(gvk.Gateway, model.NamespaceAll)
|
||||
return generate(proxy, gateways, w, updates, c.GeneratorOptions.KeepConfigLabels, c.GeneratorOptions.KeepConfigAnnotations)
|
||||
}
|
||||
|
||||
func (c GatewayGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) ([]*any.Any, []string, model.XdsLogDetails, bool, error) {
|
||||
func (c GatewayGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
type WasmpluginGenerator struct {
|
||||
Server *xds.DiscoveryServer
|
||||
type WasmPluginGenerator struct {
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c WasmpluginGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
return generate(proxy, push.AllWasmplugins, w, updates)
|
||||
func (c WasmPluginGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
wasmPlugins := c.Environment.List(gvk.WasmPlugin, model.NamespaceAll)
|
||||
return generate(proxy, wasmPlugins, w, updates, false, false)
|
||||
}
|
||||
|
||||
func (c WasmpluginGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) ([]*any.Any, []string, model.XdsLogDetails, bool, error) {
|
||||
func (c WasmPluginGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
type FallbackGenerator struct {
|
||||
Environment *model.Environment
|
||||
Server *xds.DiscoveryServer
|
||||
GeneratorOptions GeneratorOptions
|
||||
}
|
||||
|
||||
func (c FallbackGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
|
||||
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
|
||||
return make(model.Resources, 0), model.DefaultXdsLogDetails, nil
|
||||
}
|
||||
|
||||
func (c FallbackGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
|
||||
w *model.WatchedResource) (model.Resources, []string, model.XdsLogDetails, bool, error) {
|
||||
// TODO: delta implement
|
||||
return nil, nil, model.DefaultXdsLogDetails, false, nil
|
||||
}
|
||||
|
||||
func generate(proxy *model.Proxy, configs []cfg.Config, w *model.WatchedResource,
|
||||
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
|
||||
resources := make([]*any.Any, 0)
|
||||
updates *model.PushRequest, keepLabels, keepAnnotations bool) (model.Resources, model.XdsLogDetails, error) {
|
||||
resources := make(model.Resources, 0)
|
||||
if configs == nil {
|
||||
return resources, model.DefaultXdsLogDetails, nil
|
||||
}
|
||||
for _, config := range configs {
|
||||
body, err := cfg.ToProtoGogo(config.Spec)
|
||||
body, err := cfg.ToProto(config.Spec)
|
||||
if err != nil {
|
||||
return nil, model.DefaultXdsLogDetails, err
|
||||
}
|
||||
@@ -132,16 +198,28 @@ func generate(proxy *model.Proxy, configs []cfg.Config, w *model.WatchedResource
|
||||
resource := &mcp.Resource{
|
||||
Body: body,
|
||||
Metadata: &mcp.Metadata{
|
||||
Name: path.Join(config.Namespace, config.Name),
|
||||
CreateTime: createTime,
|
||||
Name: path.Join(config.Namespace, config.Name),
|
||||
CreateTime: ×tamp.Timestamp{
|
||||
Seconds: createTime.Seconds,
|
||||
Nanos: createTime.Nanos,
|
||||
},
|
||||
},
|
||||
}
|
||||
if keepLabels {
|
||||
resource.Metadata.Labels = config.Labels
|
||||
}
|
||||
if keepAnnotations {
|
||||
resource.Metadata.Annotations = config.Annotations
|
||||
}
|
||||
// nolint
|
||||
mcpAny, err := ptypes.MarshalAny(resource)
|
||||
mcpAny, err := anypb.New(resource)
|
||||
if err != nil {
|
||||
return nil, model.DefaultXdsLogDetails, err
|
||||
}
|
||||
resources = append(resources, mcpAny)
|
||||
resources = append(resources, &discovery.Resource{
|
||||
Name: resource.Metadata.Name,
|
||||
Resource: mcpAny,
|
||||
})
|
||||
}
|
||||
return resources, model.DefaultXdsLogDetails, nil
|
||||
}
|
||||
|
||||
@@ -18,114 +18,148 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/types"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
extensions "istio.io/api/extensions/v1alpha1"
|
||||
mcp "istio.io/api/mcp/v1alpha1"
|
||||
networking "istio.io/api/networking/v1alpha3"
|
||||
"istio.io/istio/pilot/pkg/model"
|
||||
"istio.io/istio/pkg/config"
|
||||
"istio.io/istio/pkg/config/schema/gvk"
|
||||
)
|
||||
|
||||
func TestGenerate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fn func() (*model.PushContext, any)
|
||||
generator model.McpResourceGenerator
|
||||
fn func() config.Config
|
||||
generator func(config.Config) model.XdsResourceGenerator
|
||||
isErr bool
|
||||
}{
|
||||
{
|
||||
name: "VirtualService",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.VirtualService,
|
||||
},
|
||||
Spec: &networking.VirtualService{},
|
||||
}
|
||||
ctx.AllVirtualServices = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: VirtualServiceGenerator{},
|
||||
isErr: false,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return VirtualServiceGenerator{Environment: env}
|
||||
},
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
name: "Gateway",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.Gateway,
|
||||
},
|
||||
Spec: &networking.Gateway{},
|
||||
}
|
||||
ctx.AllGateways = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: GatewayGenerator{},
|
||||
isErr: false,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return GatewayGenerator{Environment: env}
|
||||
},
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
name: "EnvoyFilter",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.EnvoyFilter,
|
||||
},
|
||||
Spec: &networking.EnvoyFilter{},
|
||||
}
|
||||
ctx.AllEnvoyFilters = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: EnvoyFilterGenerator{},
|
||||
isErr: false,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return EnvoyFilterGenerator{Environment: env}
|
||||
},
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
name: "DestinationRule",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.DestinationRule,
|
||||
},
|
||||
Spec: &networking.DestinationRule{},
|
||||
}
|
||||
ctx.AllDestinationRules = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: DestinationRuleGenerator{},
|
||||
isErr: false,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return DestinationRuleGenerator{Environment: env}
|
||||
},
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
name: "WasmPlugin",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.WasmPlugin,
|
||||
},
|
||||
Spec: &extensions.WasmPlugin{},
|
||||
}
|
||||
ctx.AllWasmplugins = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: WasmpluginGenerator{},
|
||||
isErr: false,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return WasmPluginGenerator{Environment: env}
|
||||
},
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
name: "ServiceEntry",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.ServiceEntry,
|
||||
},
|
||||
Spec: &networking.ServiceEntry{},
|
||||
}
|
||||
ctx.AllServiceEntries = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: ServiceEntryGenerator{},
|
||||
isErr: false,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return ServiceEntryGenerator{Environment: env}
|
||||
},
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
name: "WasmPlugin with wrong config",
|
||||
fn: func() (*model.PushContext, any) {
|
||||
ctx := model.NewPushContext()
|
||||
cfg := config.Config{
|
||||
fn: func() config.Config {
|
||||
return config.Config{
|
||||
Meta: config.Meta{
|
||||
GroupVersionKind: gvk.WasmPlugin,
|
||||
},
|
||||
Spec: "string",
|
||||
}
|
||||
ctx.AllWasmplugins = []config.Config{cfg}
|
||||
return ctx, cfg.Spec
|
||||
},
|
||||
generator: WasmpluginGenerator{},
|
||||
isErr: true,
|
||||
generator: func(c config.Config) model.XdsResourceGenerator {
|
||||
env := model.NewEnvironment()
|
||||
env.ConfigStore = model.NewFakeStore()
|
||||
_, _ = env.ConfigStore.Create(c)
|
||||
return WasmPluginGenerator{Environment: env}
|
||||
},
|
||||
isErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -133,10 +167,10 @@ func TestGenerate(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var (
|
||||
err error
|
||||
val []*anypb.Any
|
||||
val model.Resources
|
||||
)
|
||||
|
||||
pushCtx, spec := test.fn()
|
||||
cfg := test.fn()
|
||||
func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil && !test.isErr {
|
||||
@@ -144,7 +178,7 @@ func TestGenerate(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
val, _, err = test.generator.Generate(nil, pushCtx, nil, nil)
|
||||
val, _, err = test.generator(cfg).Generate(nil, nil, nil)
|
||||
if (err != nil && !test.isErr) || (err == nil && test.isErr) {
|
||||
t.Fatalf("Failed to generate config: %v", err)
|
||||
}
|
||||
@@ -155,22 +189,22 @@ func TestGenerate(t *testing.T) {
|
||||
}
|
||||
|
||||
resource := &mcp.Resource{}
|
||||
err = ptypes.UnmarshalAny(val[0], resource)
|
||||
err = ptypes.UnmarshalAny(val[0].Resource, resource)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
specType := reflect.TypeOf(spec)
|
||||
specType := reflect.TypeOf(cfg.Spec)
|
||||
if specType.Kind() == reflect.Ptr {
|
||||
specType = specType.Elem()
|
||||
}
|
||||
|
||||
target := reflect.New(specType).Interface().(proto.Message)
|
||||
if err = types.UnmarshalAny(resource.Body, target); err != nil {
|
||||
if err = ptypes.UnmarshalAny(resource.Body, target); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !test.isErr && !proto.Equal(spec.(proto.Message), target) {
|
||||
if !test.isErr && !proto.Equal(cfg.Spec.(proto.Message), target) {
|
||||
t.Fatal("failed ")
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user