update rkt and exec setconfig funcs

This commit is contained in:
Nick Ethier
2018-10-16 23:00:26 -04:00
parent 16935d6f01
commit 87748fe423
4 changed files with 18 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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