diff --git a/pkg/cmd/server/plugin/plugin.go b/pkg/cmd/server/plugin/plugin.go index f941e732e6..5a7b0356c7 100644 --- a/pkg/cmd/server/plugin/plugin.go +++ b/pkg/cmd/server/plugin/plugin.go @@ -92,7 +92,7 @@ func newPodBackupItemAction(logger logrus.FieldLogger) (interface{}, error) { return backup.NewPodAction(logger), nil } -func newServiceAccountBackupItemAction(f client.Factory) arkplugin.ServerInitializer { +func newServiceAccountBackupItemAction(f client.Factory) arkplugin.HandlerInitializer { return func(logger logrus.FieldLogger) (interface{}, error) { // TODO(ncdc): consider a k8s style WantsKubernetesClientSet initialization approach clientset, err := f.KubeClient() diff --git a/pkg/plugin/backup_item_action.go b/pkg/plugin/backup_item_action.go index 4833978230..d152d8e0c6 100644 --- a/pkg/plugin/backup_item_action.go +++ b/pkg/plugin/backup_item_action.go @@ -150,7 +150,7 @@ type BackupItemActionGRPCServer struct { } func (s *BackupItemActionGRPCServer) getImpl(name string) (arkbackup.ItemAction, error) { - impl, err := s.mux.getInstance(name) + impl, err := s.mux.getHandler(name) if err != nil { return nil, err } diff --git a/pkg/plugin/backup_item_action_test.go b/pkg/plugin/backup_item_action_test.go index aa3d163508..1cfee94cea 100644 --- a/pkg/plugin/backup_item_action_test.go +++ b/pkg/plugin/backup_item_action_test.go @@ -154,7 +154,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) { s := &BackupItemActionGRPCServer{mux: &serverMux{ serverLog: arktest.NewLogger(), - instances: map[string]interface{}{ + handlers: map[string]interface{}{ "xyz": itemAction, }, }} diff --git a/pkg/plugin/block_store.go b/pkg/plugin/block_store.go index 28fbd9bb91..57bcdce620 100644 --- a/pkg/plugin/block_store.go +++ b/pkg/plugin/block_store.go @@ -216,7 +216,7 @@ type BlockStoreGRPCServer struct { } func (s *BlockStoreGRPCServer) getImpl(name string) (cloudprovider.BlockStore, error) { - impl, err := s.mux.getInstance(name) + impl, err := s.mux.getHandler(name) if err != nil { return nil, err } diff --git a/pkg/plugin/object_store.go b/pkg/plugin/object_store.go index 2640dc716f..8ae55c7c4d 100644 --- a/pkg/plugin/object_store.go +++ b/pkg/plugin/object_store.go @@ -197,7 +197,7 @@ type ObjectStoreGRPCServer struct { } func (s *ObjectStoreGRPCServer) getImpl(name string) (cloudprovider.ObjectStore, error) { - impl, err := s.mux.getInstance(name) + impl, err := s.mux.getHandler(name) if err != nil { return nil, err } diff --git a/pkg/plugin/restore_item_action.go b/pkg/plugin/restore_item_action.go index be79e4de14..3c7a31f456 100644 --- a/pkg/plugin/restore_item_action.go +++ b/pkg/plugin/restore_item_action.go @@ -141,7 +141,7 @@ type RestoreItemActionGRPCServer struct { } func (s *RestoreItemActionGRPCServer) getImpl(name string) (restore.ItemAction, error) { - impl, err := s.mux.getInstance(name) + impl, err := s.mux.getHandler(name) if err != nil { return nil, err } diff --git a/pkg/plugin/server.go b/pkg/plugin/server.go index 0a5e2d5452..d86ed59281 100644 --- a/pkg/plugin/server.go +++ b/pkg/plugin/server.go @@ -36,28 +36,28 @@ var Handshake = plugin.HandshakeConfig{ // Server serves registered plugin implementations. type Server interface { // RegisterBackupItemAction registers a backup item action. - RegisterBackupItemAction(name string, factory ServerInitializer) Server + RegisterBackupItemAction(name string, initializer HandlerInitializer) Server // RegisterBackupItemActions registers multiple backup item actions. - RegisterBackupItemActions(map[string]ServerInitializer) Server + RegisterBackupItemActions(map[string]HandlerInitializer) Server // RegisterBlockStore registers a block store. - RegisterBlockStore(name string, factory ServerInitializer) Server + RegisterBlockStore(name string, initializer HandlerInitializer) Server // RegisterBlockStores registers multiple block stores. - RegisterBlockStores(map[string]ServerInitializer) Server + RegisterBlockStores(map[string]HandlerInitializer) Server // RegisterObjectStore registers an object store. - RegisterObjectStore(name string, factory ServerInitializer) Server + RegisterObjectStore(name string, initializer HandlerInitializer) Server // RegisterObjectStores registers multiple object stores. - RegisterObjectStores(map[string]ServerInitializer) Server + RegisterObjectStores(map[string]HandlerInitializer) Server // RegisterRestoreItemAction registers a restore item action. - RegisterRestoreItemAction(name string, factory ServerInitializer) Server + RegisterRestoreItemAction(name string, initializer HandlerInitializer) Server // RegisterRestoreItemActions registers multiple restore item actions. - RegisterRestoreItemActions(map[string]ServerInitializer) Server + RegisterRestoreItemActions(map[string]HandlerInitializer) Server // Server runs the plugin server. Serve() @@ -95,48 +95,48 @@ func NewServer(log logrus.FieldLogger) Server { } } -func (s *server) RegisterBackupItemAction(name string, factory ServerInitializer) Server { - s.backupItemAction.register(name, factory) +func (s *server) RegisterBackupItemAction(name string, initializer HandlerInitializer) Server { + s.backupItemAction.register(name, initializer) return s } -func (s *server) RegisterBackupItemActions(m map[string]ServerInitializer) Server { +func (s *server) RegisterBackupItemActions(m map[string]HandlerInitializer) Server { for name := range m { s.RegisterBackupItemAction(name, m[name]) } return s } -func (s *server) RegisterBlockStore(name string, factory ServerInitializer) Server { - s.blockStore.register(name, factory) +func (s *server) RegisterBlockStore(name string, initializer HandlerInitializer) Server { + s.blockStore.register(name, initializer) return s } -func (s *server) RegisterBlockStores(m map[string]ServerInitializer) Server { +func (s *server) RegisterBlockStores(m map[string]HandlerInitializer) Server { for name := range m { s.RegisterBlockStore(name, m[name]) } return s } -func (s *server) RegisterObjectStore(name string, factory ServerInitializer) Server { - s.objectStore.register(name, factory) +func (s *server) RegisterObjectStore(name string, initializer HandlerInitializer) Server { + s.objectStore.register(name, initializer) return s } -func (s *server) RegisterObjectStores(m map[string]ServerInitializer) Server { +func (s *server) RegisterObjectStores(m map[string]HandlerInitializer) Server { for name := range m { s.RegisterObjectStore(name, m[name]) } return s } -func (s *server) RegisterRestoreItemAction(name string, factory ServerInitializer) Server { - s.restoreItemAction.register(name, factory) +func (s *server) RegisterRestoreItemAction(name string, initializer HandlerInitializer) Server { + s.restoreItemAction.register(name, initializer) return s } -func (s *server) RegisterRestoreItemActions(m map[string]ServerInitializer) Server { +func (s *server) RegisterRestoreItemActions(m map[string]HandlerInitializer) Server { for name := range m { s.RegisterRestoreItemAction(name, m[name]) } diff --git a/pkg/plugin/server_mux.go b/pkg/plugin/server_mux.go index 4ca918ffb8..a937f71f24 100644 --- a/pkg/plugin/server_mux.go +++ b/pkg/plugin/server_mux.go @@ -6,28 +6,28 @@ import ( "k8s.io/apimachinery/pkg/util/sets" ) -// ServerInitializer is a function that initializes and returns a new instance of one of Ark's plugin interfaces +// HandlerInitializer is a function that initializes and returns a new instance of one of Ark's plugin interfaces // (ObjectStore, BlockStore, BackupItemAction, RestoreItemAction). -type ServerInitializer func(logger logrus.FieldLogger) (interface{}, error) +type HandlerInitializer func(logger logrus.FieldLogger) (interface{}, error) // serverMux manages multiple implementations of a single plugin kind, such as pod and pvc BackupItemActions. type serverMux struct { kind PluginKind - initializers map[string]ServerInitializer - instances map[string]interface{} + initializers map[string]HandlerInitializer + handlers map[string]interface{} serverLog logrus.FieldLogger } // newServerMux returns a new serverMux. func newServerMux() *serverMux { return &serverMux{ - initializers: make(map[string]ServerInitializer), - instances: make(map[string]interface{}), + initializers: make(map[string]HandlerInitializer), + handlers: make(map[string]interface{}), } } // register registers the initializer for name. -func (m *serverMux) register(name string, f ServerInitializer) { +func (m *serverMux) register(name string, f HandlerInitializer) { // TODO(ncdc): return an error on duplicate registrations for the same name. m.initializers[name] = f } @@ -42,10 +42,10 @@ func (m *serverMux) setServerLog(log logrus.FieldLogger) { m.serverLog = log } -// getInstance returns the instance for a plugin with the given name. If an instance has already been initialized, +// getHandler returns the instance for a plugin with the given name. If an instance has already been initialized, // that is returned. Otherwise, the instance is initialized by calling its initialization function. -func (m *serverMux) getInstance(name string) (interface{}, error) { - if instance, found := m.instances[name]; found { +func (m *serverMux) getHandler(name string) (interface{}, error) { + if instance, found := m.handlers[name]; found { return instance, nil } @@ -59,7 +59,7 @@ func (m *serverMux) getInstance(name string) (interface{}, error) { return nil, err } - m.instances[name] = instance + m.handlers[name] = instance - return m.instances[name], nil + return m.handlers[name], nil }