register drivers by default

Do not register mock_driver on release builds.
This commit is contained in:
Michael Schurter
2018-10-15 10:58:09 -07:00
parent 089bce5ab4
commit 7848acbea4
4 changed files with 39 additions and 28 deletions

View File

@@ -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"
)

View File

@@ -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 (

View File

@@ -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)
}

View File

@@ -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)
}