From f13b0c00a3d1c83170fffee7aabaf057f24939cd Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 27 Feb 2018 14:32:45 -0500 Subject: [PATCH 1/3] server: don't assume /ark for internal plugins If you want to test changes to the ark server without having to rebuild and redeploy the ark container, this change allows you to do something like this (assuming you've created your cloud credentials file): AWS_SHARED_CREDENTIALS_FILE=credentials-minio ark server -n heptio-ark Signed-off-by: Andy Goldstein --- pkg/plugin/manager.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/plugin/manager.go b/pkg/plugin/manager.go index 80bc1594d..ee8dbdfaa 100644 --- a/pkg/plugin/manager.go +++ b/pkg/plugin/manager.go @@ -176,16 +176,18 @@ func getPluginInstance(client *plugin.Client, kind PluginKind) (interface{}, err } func (m *manager) registerPlugins() error { + arkCommand := os.Args[0] + // first, register internal plugins for _, provider := range []string{"aws", "gcp", "azure"} { - m.pluginRegistry.register(provider, "/ark", []string{"run-plugin", "cloudprovider", provider}, PluginKindObjectStore, PluginKindBlockStore) + m.pluginRegistry.register(provider, arkCommand, []string{"run-plugin", "cloudprovider", provider}, PluginKindObjectStore, PluginKindBlockStore) } - m.pluginRegistry.register("pv", "/ark", []string{"run-plugin", string(PluginKindBackupItemAction), "pv"}, PluginKindBackupItemAction) - m.pluginRegistry.register("backup-pod", "/ark", []string{"run-plugin", string(PluginKindBackupItemAction), "pod"}, PluginKindBackupItemAction) + m.pluginRegistry.register("pv", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "pv"}, PluginKindBackupItemAction) + m.pluginRegistry.register("backup-pod", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "pod"}, PluginKindBackupItemAction) - m.pluginRegistry.register("job", "/ark", []string{"run-plugin", string(PluginKindRestoreItemAction), "job"}, PluginKindRestoreItemAction) - m.pluginRegistry.register("restore-pod", "/ark", []string{"run-plugin", string(PluginKindRestoreItemAction), "pod"}, PluginKindRestoreItemAction) - m.pluginRegistry.register("svc", "/ark", []string{"run-plugin", string(PluginKindRestoreItemAction), "svc"}, PluginKindRestoreItemAction) + m.pluginRegistry.register("job", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "job"}, PluginKindRestoreItemAction) + m.pluginRegistry.register("restore-pod", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "pod"}, PluginKindRestoreItemAction) + m.pluginRegistry.register("svc", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "svc"}, PluginKindRestoreItemAction) // second, register external plugins (these will override internal plugins, if applicable) if _, err := os.Stat(pluginDir); err != nil { From e618e0e456be263733a9179b07db920448ee0af7 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 27 Feb 2018 14:50:38 -0500 Subject: [PATCH 2/3] server: allow configurable plugin dir Signed-off-by: Andy Goldstein --- pkg/cmd/server/server.go | 8 +++++--- pkg/plugin/manager.go | 14 +++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index abb9cc4c5..5d19215f6 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -65,6 +65,7 @@ func NewCommand() *cobra.Command { var ( sortedLogLevels = getSortedLogLevels() logLevelFlag = flag.NewEnum(logrus.InfoLevel.String(), sortedLogLevels...) + pluginDir = "/plugins" ) var command = &cobra.Command{ @@ -101,7 +102,7 @@ func NewCommand() *cobra.Command { } namespace := getServerNamespace(namespaceFlag) - s, err := newServer(namespace, fmt.Sprintf("%s-%s", c.Parent().Name(), c.Name()), logger) + s, err := newServer(namespace, fmt.Sprintf("%s-%s", c.Parent().Name(), c.Name()), pluginDir, logger) cmd.CheckError(err) @@ -110,6 +111,7 @@ func NewCommand() *cobra.Command { } command.Flags().Var(logLevelFlag, "log-level", fmt.Sprintf("the level at which to log. Valid values are %s.", strings.Join(sortedLogLevels, ", "))) + command.Flags().StringVar(&pluginDir, "plugin-dir", pluginDir, "directory containing Ark plugins") return command } @@ -175,7 +177,7 @@ type server struct { pluginManager plugin.Manager } -func newServer(namespace, baseName string, logger *logrus.Logger) (*server, error) { +func newServer(namespace, baseName, pluginDir string, logger *logrus.Logger) (*server, error) { clientConfig, err := client.Config("", "", baseName) if err != nil { return nil, err @@ -191,7 +193,7 @@ func newServer(namespace, baseName string, logger *logrus.Logger) (*server, erro return nil, errors.WithStack(err) } - pluginManager, err := plugin.NewManager(logger, logger.Level) + pluginManager, err := plugin.NewManager(logger, logger.Level, pluginDir) if err != nil { return nil, err } diff --git a/pkg/plugin/manager.go b/pkg/plugin/manager.go index ee8dbdfaa..7bd6a637a 100644 --- a/pkg/plugin/manager.go +++ b/pkg/plugin/manager.go @@ -74,8 +74,6 @@ const ( // PluginKindRestoreItemAction is the Kind string for // a Restore ItemAction plugin. PluginKindRestoreItemAction PluginKind = "restoreitemaction" - - pluginDir = "/plugins" ) var AllPluginKinds = []PluginKind{ @@ -132,15 +130,17 @@ type manager struct { logLevel logrus.Level pluginRegistry *registry clientStore *clientStore + pluginDir string } // NewManager constructs a manager for getting plugin implementations. -func NewManager(logger logrus.FieldLogger, level logrus.Level) (Manager, error) { +func NewManager(logger logrus.FieldLogger, level logrus.Level, pluginDir string) (Manager, error) { m := &manager{ logger: logger, logLevel: level, pluginRegistry: newRegistry(), clientStore: newClientStore(), + pluginDir: pluginDir, } if err := m.registerPlugins(); err != nil { @@ -190,14 +190,14 @@ func (m *manager) registerPlugins() error { m.pluginRegistry.register("svc", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "svc"}, PluginKindRestoreItemAction) // second, register external plugins (these will override internal plugins, if applicable) - if _, err := os.Stat(pluginDir); err != nil { + if _, err := os.Stat(m.pluginDir); err != nil { if os.IsNotExist(err) { return nil } return err } - files, err := ioutil.ReadDir(pluginDir) + files, err := ioutil.ReadDir(m.pluginDir) if err != nil { return err } @@ -209,9 +209,9 @@ func (m *manager) registerPlugins() error { } if kind == PluginKindCloudProvider { - m.pluginRegistry.register(name, filepath.Join(pluginDir, file.Name()), nil, PluginKindObjectStore, PluginKindBlockStore) + m.pluginRegistry.register(name, filepath.Join(m.pluginDir, file.Name()), nil, PluginKindObjectStore, PluginKindBlockStore) } else { - m.pluginRegistry.register(name, filepath.Join(pluginDir, file.Name()), nil, kind) + m.pluginRegistry.register(name, filepath.Join(m.pluginDir, file.Name()), nil, kind) } } From e3c40a1de7c4977dcb75303e8d20f8b883bcfb64 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Tue, 27 Feb 2018 14:51:13 -0500 Subject: [PATCH 3/3] Regen docs Signed-off-by: Andy Goldstein --- docs/cli-reference/ark_server.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/cli-reference/ark_server.md b/docs/cli-reference/ark_server.md index baeedb519..46bf223cd 100644 --- a/docs/cli-reference/ark_server.md +++ b/docs/cli-reference/ark_server.md @@ -14,8 +14,9 @@ ark server [flags] ### Options ``` - -h, --help help for server - --log-level the level at which to log. Valid values are debug, info, warning, error, fatal, panic. (default info) + -h, --help help for server + --log-level the level at which to log. Valid values are debug, info, warning, error, fatal, panic. (default info) + --plugin-dir string directory containing Ark plugins (default "/plugins") ``` ### Options inherited from parent commands