server: allow configurable plugin dir
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>pull/334/head
parent
f13b0c00a3
commit
e618e0e456
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue