diff --git a/drivers/exec/driver.go b/drivers/exec/driver.go index 231382a32..ad4c3c40e 100644 --- a/drivers/exec/driver.go +++ b/drivers/exec/driver.go @@ -72,6 +72,9 @@ type ExecDriver struct { // config is the driver configuration set by the SetConfig RPC config *Config + // nomadConfig is the client config from nomad + nomadConfig *base.NomadConfig + // tasks is the in memory datastore mapping taskIDs to execDriverHandles tasks *taskStore @@ -132,13 +135,14 @@ func (*ExecDriver) ConfigSchema() (*hclspec.Spec, error) { return configSpec, nil } -func (d *ExecDriver) SetConfig(data []byte) error { +func (d *ExecDriver) SetConfig(data []byte, cfg *base.NomadConfig) error { var config Config if err := base.MsgPackDecode(data, &config); err != nil { return err } d.config = &config + d.nomadConfig = cfg return nil } @@ -240,7 +244,7 @@ func (d *ExecDriver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *c } // TODO: best way to pass port ranges in from client config - exec, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, 14000, 14512, executorConfig) + exec, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, d.nomadConfig, executorConfig) if err != nil { return nil, nil, err } diff --git a/drivers/rawexec/driver.go b/drivers/rawexec/driver.go index b5c0db551..8ac3567bf 100644 --- a/drivers/rawexec/driver.go +++ b/drivers/rawexec/driver.go @@ -301,7 +301,7 @@ func (r *RawExecDriver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, LogLevel: "debug", } - exec, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, r.nomadConfig.ClientMinPort, r.nomadConfig.ClientMaxPort, executorConfig) + exec, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, r.nomadConfig, executorConfig) if err != nil { return nil, nil, fmt.Errorf("failed to create executor: %v", err) } diff --git a/drivers/rkt/driver.go b/drivers/rkt/driver.go index 211a1075a..36168964d 100644 --- a/drivers/rkt/driver.go +++ b/drivers/rkt/driver.go @@ -153,6 +153,9 @@ type RktDriver struct { // config is the driver configuration set by the SetConfig RPC config *Config + // nomadConfig is the client config from nomad + nomadConfig *base.NomadConfig + // tasks is the in memory datastore mapping taskIDs to rktTaskHandles tasks *taskStore @@ -190,13 +193,14 @@ func (d *RktDriver) ConfigSchema() (*hclspec.Spec, error) { return configSpec, nil } -func (d *RktDriver) SetConfig(data []byte) error { +func (d *RktDriver) SetConfig(data []byte, cfg *base.NomadConfig) error { var config Config if err := base.MsgPackDecode(data, &config); err != nil { return err } d.config = &config + d.nomadConfig = cfg return nil } @@ -569,8 +573,7 @@ func (d *RktDriver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cs LogLevel: "debug", } - // TODO: best way to pass port ranges in from client config - execImpl, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, 14000, 14512, executorConfig) + execImpl, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, d.nomadConfig, executorConfig) if err != nil { return nil, nil, err } diff --git a/plugins/drivers/utils/utils.go b/plugins/drivers/utils/utils.go index 4ace338ff..4f5b64901 100644 --- a/plugins/drivers/utils/utils.go +++ b/plugins/drivers/utils/utils.go @@ -14,6 +14,7 @@ import ( dstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/helper/discover" "github.com/hashicorp/nomad/nomad/structs" + "github.com/hashicorp/nomad/plugins/base" ) // CgroupsMounted returns true if the cgroups are mounted on a system otherwise @@ -25,7 +26,7 @@ func CgroupsMounted(node *structs.Node) bool { // CreateExecutor launches an executor plugin and returns an instance of the // Executor interface -func CreateExecutor(w io.Writer, level hclog.Level, CMinPort, CMaxPort uint, +func CreateExecutor(w io.Writer, level hclog.Level, nomadConfig *base.NomadConfig, executorConfig *dstructs.ExecutorConfig) (executor.Executor, *plugin.Client, error) { c, err := json.Marshal(executorConfig) @@ -42,8 +43,8 @@ func CreateExecutor(w io.Writer, level hclog.Level, CMinPort, CMaxPort uint, } config.HandshakeConfig = driver.HandshakeConfig config.Plugins = driver.GetPluginMap(w, level, executorConfig.FSIsolation) - config.MaxPort = CMaxPort - config.MinPort = CMinPort + config.MaxPort = nomadConfig.ClientMaxPort + config.MinPort = nomadConfig.ClientMinPort // setting the setsid of the plugin process so that it doesn't get signals sent to // the nomad client. @@ -65,6 +66,7 @@ func CreateExecutor(w io.Writer, level hclog.Level, CMinPort, CMaxPort uint, return executorPlugin, executorClient, nil } +// CreateExecutorWithConfig launches a plugin with a given plugin config func CreateExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (executor.Executor, *plugin.Client, error) { config.HandshakeConfig = driver.HandshakeConfig