diff --git a/command/agent/plugin_internal_catalog.go b/command/agent/plugin_internal_catalog.go deleted file mode 100644 index 034dea2cf..000000000 --- a/command/agent/plugin_internal_catalog.go +++ /dev/null @@ -1,12 +0,0 @@ -package agent - -import ( - - // Each internal plugin has an init func which registers itself with the - // plugin catalog. Since the plugin implementations are not imported by the - // client or server they must be referenced here so plugin registration - // occures. - - // raw_exec driver - _ "github.com/hashicorp/nomad/drivers/rawexec" -) diff --git a/drivers/rawexec/driver.go b/drivers/rawexec/driver.go index 7e8fc2643..fce320c8d 100644 --- a/drivers/rawexec/driver.go +++ b/drivers/rawexec/driver.go @@ -17,7 +17,6 @@ import ( "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" - "github.com/hashicorp/nomad/plugins/shared/catalog" "github.com/hashicorp/nomad/plugins/shared/hclspec" "github.com/hashicorp/nomad/plugins/shared/loader" "golang.org/x/net/context" @@ -25,25 +24,27 @@ import ( // When the package is loaded the driver is registered as an internal plugin // with the plugin catalog -func init() { - catalog.RegisterDeferredConfig(loader.PluginID{ +var ( + PluginID = loader.PluginID{ Name: pluginName, PluginType: base.PluginTypeDriver, - }, &loader.InternalPluginConfig{ + } + + PluginConfig = &loader.InternalPluginConfig{ Config: map[string]interface{}{}, Factory: func(l hclog.Logger) interface{} { return NewRawExecDriver(l) }, - }, - func(opts map[string]string) (map[string]interface{}, error) { - conf := map[string]interface{}{} - if v, err := strconv.ParseBool(opts["driver.raw_exec.enable"]); err == nil { - conf["enabled"] = v - } - if v, err := strconv.ParseBool(opts["driver.raw_exec.no_cgroups"]); err == nil { - conf["no_cgroups"] = v - } - return conf, nil - }, - ) + } +) + +func PluginLoader(opts map[string]string) (map[string]interface{}, error) { + conf := map[string]interface{}{} + if v, err := strconv.ParseBool(opts["driver.raw_exec.enable"]); err == nil { + conf["enabled"] = v + } + if v, err := strconv.ParseBool(opts["driver.raw_exec.no_cgroups"]); err == nil { + conf["no_cgroups"] = v + } + return conf, nil } const ( diff --git a/plugins/shared/catalog/register.go b/plugins/shared/catalog/register.go new file mode 100644 index 000000000..553ff2aef --- /dev/null +++ b/plugins/shared/catalog/register.go @@ -0,0 +1,10 @@ +package catalog + +import "github.com/hashicorp/nomad/drivers/rawexec" + +// This file is where all builtin plugins should be registered in the catalog. +// Plugins with build restrictions should be placed in the appropriate +// register_XXX.go file. +func init() { + RegisterDeferredConfig(rawexec.PluginID, rawexec.PluginConfig, rawexec.PluginLoader) +} diff --git a/plugins/shared/catalog/register_testing.go b/plugins/shared/catalog/register_testing.go new file mode 100644 index 000000000..d3d58c925 --- /dev/null +++ b/plugins/shared/catalog/register_testing.go @@ -0,0 +1,12 @@ +// +build !release + +package catalog + +import "github.com/hashicorp/nomad/drivers/mock" + +// Register the mock driver with the builtin driver plugin catalog. All builtin +// plugins that are intended for production use should be registered in +// register.go as this file is not built as part of a release. +func init() { + Register(mock.PluginID, mock.PluginConfig) +}