From b1c0e9c49b15d54d053603002c4066aacc318602 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Thu, 21 Mar 2019 13:32:18 -0600 Subject: [PATCH] update plugins to work with updated go-plugin (#1308) * update plugins to work with updated go-plugin Signed-off-by: Steve Kriss --- pkg/plugin/framework/backup_item_action.go | 9 ++--- pkg/plugin/framework/block_store.go | 9 ++--- pkg/plugin/framework/object_store.go | 9 ++--- pkg/plugin/framework/plugin_lister.go | 8 ++--- pkg/plugin/framework/plugin_types_test.go | 39 +++++++++++++++++++++ pkg/plugin/framework/restore_item_action.go | 9 ++--- 6 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 pkg/plugin/framework/plugin_types_test.go diff --git a/pkg/plugin/framework/backup_item_action.go b/pkg/plugin/framework/backup_item_action.go index e1e6e0766..3d4be3f13 100644 --- a/pkg/plugin/framework/backup_item_action.go +++ b/pkg/plugin/framework/backup_item_action.go @@ -18,6 +18,7 @@ package framework import ( "github.com/hashicorp/go-plugin" + "golang.org/x/net/context" "google.golang.org/grpc" proto "github.com/heptio/velero/pkg/plugin/generated" @@ -32,12 +33,12 @@ type BackupItemActionPlugin struct { } // GRPCClient returns a clientDispenser for BackupItemAction gRPC clients. -func (p *BackupItemActionPlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error) { - return newClientDispenser(p.clientLogger, c, newBackupItemActionGRPCClient), nil +func (p *BackupItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { + return newClientDispenser(p.clientLogger, clientConn, newBackupItemActionGRPCClient), nil } // GRPCServer registers a BackupItemAction gRPC server. -func (p *BackupItemActionPlugin) GRPCServer(s *grpc.Server) error { - proto.RegisterBackupItemActionServer(s, &BackupItemActionGRPCServer{mux: p.serverMux}) +func (p *BackupItemActionPlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error { + proto.RegisterBackupItemActionServer(server, &BackupItemActionGRPCServer{mux: p.serverMux}) return nil } diff --git a/pkg/plugin/framework/block_store.go b/pkg/plugin/framework/block_store.go index 1e5387734..6b19e487b 100644 --- a/pkg/plugin/framework/block_store.go +++ b/pkg/plugin/framework/block_store.go @@ -18,6 +18,7 @@ package framework import ( "github.com/hashicorp/go-plugin" + "golang.org/x/net/context" "google.golang.org/grpc" proto "github.com/heptio/velero/pkg/plugin/generated" @@ -32,12 +33,12 @@ type BlockStorePlugin struct { } // GRPCClient returns a BlockStore gRPC client. -func (p *BlockStorePlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error) { - return newClientDispenser(p.clientLogger, c, newBlockStoreGRPCClient), nil +func (p *BlockStorePlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { + return newClientDispenser(p.clientLogger, clientConn, newBlockStoreGRPCClient), nil } // GRPCServer registers a BlockStore gRPC server. -func (p *BlockStorePlugin) GRPCServer(s *grpc.Server) error { - proto.RegisterBlockStoreServer(s, &BlockStoreGRPCServer{mux: p.serverMux}) +func (p *BlockStorePlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error { + proto.RegisterBlockStoreServer(server, &BlockStoreGRPCServer{mux: p.serverMux}) return nil } diff --git a/pkg/plugin/framework/object_store.go b/pkg/plugin/framework/object_store.go index 16ab3dcf2..9bb16c0ca 100644 --- a/pkg/plugin/framework/object_store.go +++ b/pkg/plugin/framework/object_store.go @@ -18,6 +18,7 @@ package framework import ( "github.com/hashicorp/go-plugin" + "golang.org/x/net/context" "google.golang.org/grpc" proto "github.com/heptio/velero/pkg/plugin/generated" @@ -32,13 +33,13 @@ type ObjectStorePlugin struct { } // GRPCClient returns an ObjectStore gRPC client. -func (p *ObjectStorePlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error) { - return newClientDispenser(p.clientLogger, c, newObjectStoreGRPCClient), nil +func (p *ObjectStorePlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { + return newClientDispenser(p.clientLogger, clientConn, newObjectStoreGRPCClient), nil } // GRPCServer registers an ObjectStore gRPC server. -func (p *ObjectStorePlugin) GRPCServer(s *grpc.Server) error { - proto.RegisterObjectStoreServer(s, &ObjectStoreGRPCServer{mux: p.serverMux}) +func (p *ObjectStorePlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error { + proto.RegisterObjectStoreServer(server, &ObjectStoreGRPCServer{mux: p.serverMux}) return nil } diff --git a/pkg/plugin/framework/plugin_lister.go b/pkg/plugin/framework/plugin_lister.go index 6298fa022..67d7f2345 100644 --- a/pkg/plugin/framework/plugin_lister.go +++ b/pkg/plugin/framework/plugin_lister.go @@ -68,8 +68,8 @@ func NewPluginListerPlugin(impl PluginLister) *PluginListerPlugin { ////////////////////////////////////////////////////////////////////////////// // GRPCClient returns a PluginLister gRPC client. -func (p *PluginListerPlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error) { - return &PluginListerGRPCClient{grpcClient: proto.NewPluginListerClient(c)}, nil +func (p *PluginListerPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { + return &PluginListerGRPCClient{grpcClient: proto.NewPluginListerClient(clientConn)}, nil } // PluginListerGRPCClient implements PluginLister and uses a gRPC client to make calls to the plugin server. @@ -106,8 +106,8 @@ func (c *PluginListerGRPCClient) ListPlugins() ([]PluginIdentifier, error) { ////////////////////////////////////////////////////////////////////////////// // GRPCServer registers a PluginLister gRPC server. -func (p *PluginListerPlugin) GRPCServer(s *grpc.Server) error { - proto.RegisterPluginListerServer(s, &PluginListerGRPCServer{impl: p.impl}) +func (p *PluginListerPlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error { + proto.RegisterPluginListerServer(server, &PluginListerGRPCServer{impl: p.impl}) return nil } diff --git a/pkg/plugin/framework/plugin_types_test.go b/pkg/plugin/framework/plugin_types_test.go new file mode 100644 index 000000000..2b0f108fc --- /dev/null +++ b/pkg/plugin/framework/plugin_types_test.go @@ -0,0 +1,39 @@ +/* +Copyright 2019 the Velero contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package framework + +import ( + "testing" + + "github.com/hashicorp/go-plugin" + "github.com/stretchr/testify/assert" +) + +func TestPluginImplementationsAreGRPCPlugins(t *testing.T) { + pluginImpls := []interface{}{ + new(BlockStorePlugin), + new(BackupItemActionPlugin), + new(ObjectStorePlugin), + new(PluginListerPlugin), + new(RestoreItemActionPlugin), + } + + for _, impl := range pluginImpls { + _, ok := impl.(plugin.GRPCPlugin) + assert.True(t, ok, "plugin implementation %T does not implement the go-plugin.GRPCPlugin interface", impl) + } +} diff --git a/pkg/plugin/framework/restore_item_action.go b/pkg/plugin/framework/restore_item_action.go index 6dce8cb55..bfc27955d 100644 --- a/pkg/plugin/framework/restore_item_action.go +++ b/pkg/plugin/framework/restore_item_action.go @@ -18,6 +18,7 @@ package framework import ( "github.com/hashicorp/go-plugin" + "golang.org/x/net/context" "google.golang.org/grpc" proto "github.com/heptio/velero/pkg/plugin/generated" @@ -32,12 +33,12 @@ type RestoreItemActionPlugin struct { } // GRPCClient returns a RestoreItemAction gRPC client. -func (p *RestoreItemActionPlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error) { - return newClientDispenser(p.clientLogger, c, newRestoreItemActionGRPCClient), nil +func (p *RestoreItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { + return newClientDispenser(p.clientLogger, clientConn, newRestoreItemActionGRPCClient), nil } // GRPCServer registers a RestoreItemAction gRPC server. -func (p *RestoreItemActionPlugin) GRPCServer(s *grpc.Server) error { - proto.RegisterRestoreItemActionServer(s, &RestoreItemActionGRPCServer{mux: p.serverMux}) +func (p *RestoreItemActionPlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error { + proto.RegisterRestoreItemActionServer(server, &RestoreItemActionGRPCServer{mux: p.serverMux}) return nil }