From 75d333fe024fb9bd5236dd0495ef7ab64968e45d Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Thu, 29 Nov 2018 14:33:39 +0100 Subject: [PATCH] client: Move executor plugins into own package --- client/driver/exec.go | 5 +++-- .../driver/{ => executor_plugin}/executor_plugin.go | 2 +- .../executor_plugin_pre_0_9_0.go | 2 +- client/driver/{ => executor_plugin}/plugins.go | 2 +- client/driver/java.go | 5 +++-- client/driver/qemu.go | 5 +++-- client/driver/raw_exec.go | 5 +++-- client/driver/utils.go | 11 ++++++----- command/executor_plugin.go | 6 +++--- plugins/drivers/utils/utils.go | 12 ++++++------ 10 files changed, 30 insertions(+), 25 deletions(-) rename client/driver/{ => executor_plugin}/executor_plugin.go (99%) rename client/driver/{ => executor_plugin}/executor_plugin_pre_0_9_0.go (99%) rename client/driver/{ => executor_plugin}/plugins.go (98%) diff --git a/client/driver/exec.go b/client/driver/exec.go index 6ab770b3c..01e04bce1 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/allocdir" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/executor" @@ -175,7 +176,7 @@ type execId struct { KillTimeout time.Duration MaxKillTimeout time.Duration UserPid int - PluginConfig *PluginReattachConfig + PluginConfig *executorplugin.PluginReattachConfig } func (d *ExecDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, error) { @@ -222,7 +223,7 @@ func (h *execHandle) ID() string { Version: h.version, KillTimeout: h.killTimeout, MaxKillTimeout: h.maxKillTimeout, - PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), + PluginConfig: executorplugin.NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, } diff --git a/client/driver/executor_plugin.go b/client/driver/executor_plugin/executor_plugin.go similarity index 99% rename from client/driver/executor_plugin.go rename to client/driver/executor_plugin/executor_plugin.go index cb0fca7ca..70d3fa8c2 100644 --- a/client/driver/executor_plugin.go +++ b/client/driver/executor_plugin/executor_plugin.go @@ -1,4 +1,4 @@ -package driver +package executorplugin import ( "encoding/gob" diff --git a/client/driver/executor_plugin_pre_0_9_0.go b/client/driver/executor_plugin/executor_plugin_pre_0_9_0.go similarity index 99% rename from client/driver/executor_plugin_pre_0_9_0.go rename to client/driver/executor_plugin/executor_plugin_pre_0_9_0.go index 9692adc54..ad3f53617 100644 --- a/client/driver/executor_plugin_pre_0_9_0.go +++ b/client/driver/executor_plugin/executor_plugin_pre_0_9_0.go @@ -1,4 +1,4 @@ -package driver +package executorplugin /* import ( diff --git a/client/driver/plugins.go b/client/driver/executor_plugin/plugins.go similarity index 98% rename from client/driver/plugins.go rename to client/driver/executor_plugin/plugins.go index 7385a18e1..da8f439d4 100644 --- a/client/driver/plugins.go +++ b/client/driver/executor_plugin/plugins.go @@ -1,4 +1,4 @@ -package driver +package executorplugin import ( "io" diff --git a/client/driver/java.go b/client/driver/java.go index f2c769c0e..7766d27d2 100644 --- a/client/driver/java.go +++ b/client/driver/java.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/go-plugin" "github.com/mitchellh/mapstructure" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/client/fingerprint" cstructs "github.com/hashicorp/nomad/client/structs" @@ -307,7 +308,7 @@ type javaId struct { Version string KillTimeout time.Duration MaxKillTimeout time.Duration - PluginConfig *PluginReattachConfig + PluginConfig *executorplugin.PluginReattachConfig TaskDir string UserPid int ShutdownSignal string @@ -359,7 +360,7 @@ func (h *javaHandle) ID() string { Version: h.version, KillTimeout: h.killTimeout, MaxKillTimeout: h.maxKillTimeout, - PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), + PluginConfig: executorplugin.NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, TaskDir: h.taskDir, ShutdownSignal: h.shutdownSignal, diff --git a/client/driver/qemu.go b/client/driver/qemu.go index e77f4209c..21c84d833 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -17,6 +17,7 @@ import ( "github.com/coreos/go-semver/semver" plugin "github.com/hashicorp/go-plugin" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/client/fingerprint" cstructs "github.com/hashicorp/nomad/client/structs" @@ -372,7 +373,7 @@ type qemuId struct { KillTimeout time.Duration MaxKillTimeout time.Duration UserPid int - PluginConfig *PluginReattachConfig + PluginConfig *executorplugin.PluginReattachConfig ShutdownSignal string } @@ -421,7 +422,7 @@ func (h *qemuHandle) ID() string { Version: h.version, KillTimeout: h.killTimeout, MaxKillTimeout: h.maxKillTimeout, - PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), + PluginConfig: executorplugin.NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, ShutdownSignal: h.shutdownSignal, } diff --git a/client/driver/raw_exec.go b/client/driver/raw_exec.go index 426507e2e..5da9c34b4 100644 --- a/client/driver/raw_exec.go +++ b/client/driver/raw_exec.go @@ -14,6 +14,7 @@ import ( multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/allocdir" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/client/fingerprint" cstructs "github.com/hashicorp/nomad/client/structs" @@ -201,7 +202,7 @@ type rawExecId struct { KillTimeout time.Duration MaxKillTimeout time.Duration UserPid int - PluginConfig *PluginReattachConfig + PluginConfig *executorplugin.PluginReattachConfig ShutdownSignal string } @@ -252,7 +253,7 @@ func (h *rawExecHandle) ID() string { Version: h.version, KillTimeout: h.killTimeout, MaxKillTimeout: h.maxKillTimeout, - PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), + PluginConfig: executorplugin.NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, ShutdownSignal: h.shutdownSignal, } diff --git a/client/driver/utils.go b/client/driver/utils.go index 2c02a0885..9b1c3c415 100644 --- a/client/driver/utils.go +++ b/client/driver/utils.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/config" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/discover" @@ -45,8 +46,8 @@ func createExecutor(w io.Writer, clientConfig *config.Config, config := &plugin.ClientConfig{ Cmd: exec.Command(bin, "executor", string(c)), } - config.HandshakeConfig = HandshakeConfig - config.Plugins = GetPluginMap(w, hclog.LevelFromString(clientConfig.LogLevel), executorConfig.FSIsolation) + config.HandshakeConfig = executorplugin.HandshakeConfig + config.Plugins = executorplugin.GetPluginMap(w, hclog.LevelFromString(clientConfig.LogLevel), executorConfig.FSIsolation) config.MaxPort = clientConfig.ClientMaxPort config.MinPort = clientConfig.ClientMinPort @@ -71,11 +72,11 @@ func createExecutor(w io.Writer, clientConfig *config.Config, } func createExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (executor.Executor, *plugin.Client, error) { - config.HandshakeConfig = HandshakeConfig + config.HandshakeConfig = executorplugin.HandshakeConfig // Setting this to DEBUG since the log level at the executor server process // is already set, and this effects only the executor client. - config.Plugins = GetPluginMap(w, hclog.Debug, false) + config.Plugins = executorplugin.GetPluginMap(w, hclog.Debug, false) executorClient := plugin.NewClient(config) rpcClient, err := executorClient.Client() @@ -87,7 +88,7 @@ func createExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (executo if err != nil { return nil, nil, fmt.Errorf("unable to dispense the executor plugin: %v", err) } - executorPlugin, ok := raw.(*ExecutorRPC) + executorPlugin, ok := raw.(*executorplugin.ExecutorRPC) if !ok { return nil, nil, fmt.Errorf("unexpected executor rpc type: %T", raw) } diff --git a/command/executor_plugin.go b/command/executor_plugin.go index 2900c94c0..a7969a074 100644 --- a/command/executor_plugin.go +++ b/command/executor_plugin.go @@ -8,7 +8,7 @@ import ( hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/client/driver" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" ) @@ -43,8 +43,8 @@ func (e *ExecutorPluginCommand) Run(args []string) int { return 1 } plugin.Serve(&plugin.ServeConfig{ - HandshakeConfig: driver.HandshakeConfig, - Plugins: driver.GetPluginMap( + HandshakeConfig: executorplugin.HandshakeConfig, + Plugins: executorplugin.GetPluginMap( stdo, hclog.LevelFromString(executorConfig.LogLevel), executorConfig.FSIsolation, diff --git a/plugins/drivers/utils/utils.go b/plugins/drivers/utils/utils.go index 68f62c814..6328a38ee 100644 --- a/plugins/drivers/utils/utils.go +++ b/plugins/drivers/utils/utils.go @@ -12,7 +12,7 @@ import ( plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/client/driver" + "github.com/hashicorp/nomad/client/driver/executor_plugin" dstructs "github.com/hashicorp/nomad/client/driver/structs" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/env" @@ -79,8 +79,8 @@ func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDri config := &plugin.ClientConfig{ Cmd: exec.Command(bin, "executor", string(c)), } - config.HandshakeConfig = driver.HandshakeConfig - config.Plugins = driver.GetPluginMap(w, level, executorConfig.FSIsolation) + config.HandshakeConfig = executorplugin.HandshakeConfig + config.Plugins = executorplugin.GetPluginMap(w, level, executorConfig.FSIsolation) if driverConfig != nil { config.MaxPort = driverConfig.ClientMaxPort @@ -112,11 +112,11 @@ func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDri // 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 + config.HandshakeConfig = executorplugin.HandshakeConfig // Setting this to DEBUG since the log level at the executor server process // is already set, and this effects only the executor client. - config.Plugins = driver.GetPluginMap(w, hclog.Debug, false) + config.Plugins = executorplugin.GetPluginMap(w, hclog.Debug, false) executorClient := plugin.NewClient(config) rpcClient, err := executorClient.Client() @@ -128,7 +128,7 @@ func CreateExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (executo if err != nil { return nil, nil, fmt.Errorf("unable to dispense the executor plugin: %v", err) } - executorPlugin, ok := raw.(*driver.ExecutorRPC) + executorPlugin, ok := raw.(*executorplugin.ExecutorRPC) if !ok { return nil, nil, fmt.Errorf("unexpected executor rpc type: %T", raw) }