From a5e1e4b59ee0363bc9beaa8f2f5961fa38ecf0d6 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 31 Oct 2018 13:52:15 -0400 Subject: [PATCH 1/2] Register exec driver plugin among some fixes Namely, remove the `enabled` configuration flag, as it's specific to `raw_exec` driver. Also, pass resource limits to underlying call. --- drivers/exec/driver.go | 44 ++++++++++++------------------ plugins/shared/catalog/register.go | 2 ++ 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/exec/driver.go b/drivers/exec/driver.go index 468b80890..cbdf99db0 100644 --- a/drivers/exec/driver.go +++ b/drivers/exec/driver.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" "github.com/hashicorp/nomad/plugins/shared/hclspec" + "github.com/hashicorp/nomad/plugins/shared/loader" "golang.org/x/net/context" ) @@ -30,6 +31,13 @@ const ( ) var ( + // PluginID is the rawexec plugin metadata registered in the plugin + // catalog. + PluginID = loader.PluginID{ + Name: pluginName, + PluginType: base.PluginTypeDriver, + } + // pluginInfo is the response returned for the PluginInfo RPC pluginInfo = &base.PluginInfoResponse{ Type: base.PluginTypeDriver, @@ -39,12 +47,7 @@ var ( } // configSpec is the hcl specification returned by the ConfigSchema RPC - configSpec = hclspec.NewObject(map[string]*hclspec.Spec{ - "enabled": hclspec.NewDefault( - hclspec.NewAttr("enabled", "bool", false), - hclspec.NewLiteral("true"), - ), - }) + configSpec = hclspec.NewObject(map[string]*hclspec.Spec{}) // taskConfigSpec is the hcl specification for the driver config section of // a task within a job. It is returned in the TaskConfigSchema RPC @@ -69,9 +72,6 @@ type ExecDriver struct { // event can be broadcast to all callers eventer *eventer.Eventer - // config is the driver configuration set by the SetConfig RPC - config *Config - // nomadConfig is the client config from nomad nomadConfig *base.ClientDriverConfig @@ -91,12 +91,6 @@ type ExecDriver struct { logger hclog.Logger } -// Config is the driver configuration set by the SetConfig RPC call -type Config struct { - // Enabled is set to true to enable the driver - Enabled bool `cty:"enabled"` -} - // TaskConfig is the driver configuration of a task within a job type TaskConfig struct { Command string `cty:"command"` @@ -119,7 +113,6 @@ func NewExecDriver(logger hclog.Logger) drivers.DriverPlugin { logger = logger.Named(pluginName) return &ExecDriver{ eventer: eventer.NewEventer(ctx, logger), - config: &Config{}, tasks: newTaskStore(), ctx: ctx, signalShutdown: cancel, @@ -135,13 +128,7 @@ func (*ExecDriver) ConfigSchema() (*hclspec.Spec, error) { return configSpec, nil } -func (d *ExecDriver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error { - var config Config - if err := base.MsgPackDecode(data, &config); err != nil { - return err - } - - d.config = &config +func (d *ExecDriver) SetConfig(_ []byte, cfg *base.ClientAgentConfig) error { if cfg != nil { d.nomadConfig = cfg.Driver } @@ -257,9 +244,14 @@ func (d *ExecDriver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *c Env: cfg.EnvList(), User: cfg.User, ResourceLimits: true, - TaskDir: cfg.TaskDir().Dir, - StdoutPath: cfg.StdoutPath, - StderrPath: cfg.StderrPath, + Resources: &executor.Resources{ + CPU: int(cfg.Resources.LinuxResources.CPUShares), + MemoryMB: int(drivers.BytesToMB(cfg.Resources.LinuxResources.MemoryLimitBytes)), + DiskMB: cfg.Resources.NomadResources.DiskMB, + }, + TaskDir: cfg.TaskDir().Dir, + StdoutPath: cfg.StdoutPath, + StderrPath: cfg.StderrPath, } ps, err := exec.Launch(execCmd) diff --git a/plugins/shared/catalog/register.go b/plugins/shared/catalog/register.go index 1659be927..1ea6ce8d2 100644 --- a/plugins/shared/catalog/register.go +++ b/plugins/shared/catalog/register.go @@ -1,6 +1,7 @@ package catalog import ( + "github.com/hashicorp/nomad/drivers/exec" "github.com/hashicorp/nomad/drivers/qemu" "github.com/hashicorp/nomad/drivers/rawexec" ) @@ -10,5 +11,6 @@ import ( // register_XXX.go file. func init() { RegisterDeferredConfig(rawexec.PluginID, rawexec.PluginConfig, rawexec.PluginLoader) + Register(exec.PluginID, exec.PluginConfig) Register(qemu.PluginID, qemu.PluginConfig) } From 6b79e5bd12140168caa3046fbf535678c31c7af4 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 2 Nov 2018 08:39:18 -0400 Subject: [PATCH 2/2] add plugin config --- drivers/exec/driver.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/exec/driver.go b/drivers/exec/driver.go index cbdf99db0..28867f43d 100644 --- a/drivers/exec/driver.go +++ b/drivers/exec/driver.go @@ -31,13 +31,20 @@ const ( ) var ( - // PluginID is the rawexec plugin metadata registered in the plugin + // PluginID is the exec plugin metadata registered in the plugin // catalog. PluginID = loader.PluginID{ Name: pluginName, PluginType: base.PluginTypeDriver, } + // PluginConfig is the exec driver factory function registered in the + // plugin catalog. + PluginConfig = &loader.InternalPluginConfig{ + Config: map[string]interface{}{}, + Factory: func(l hclog.Logger) interface{} { return NewExecDriver(l) }, + } + // pluginInfo is the response returned for the PluginInfo RPC pluginInfo = &base.PluginInfoResponse{ Type: base.PluginTypeDriver,