diff --git a/client/alloc_runner.go b/client/alloc_runner.go index dd0f1f8db..4eb0d9b87 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -66,6 +66,7 @@ type AllocRunner struct { // allocRunnerState is used to snapshot the state of the alloc runner type allocRunnerState struct { + Version string Alloc *structs.Allocation AllocClientStatus string AllocClientDescription string @@ -181,6 +182,7 @@ func (r *AllocRunner) saveAllocRunnerState() error { r.ctxLock.Unlock() snap := allocRunnerState{ + Version: r.config.Version, Alloc: alloc, Context: ctx, AllocClientStatus: allocClientStatus, diff --git a/client/config/config.go b/client/config/config.go index b78dc24f2..ef5a2b212 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -70,6 +70,9 @@ type Config struct { // // namespace.option = value Options map[string]string + + // Version is the version of the Nomad client + Version string } func (c *Config) Copy() *Config { diff --git a/client/driver/docker.go b/client/driver/docker.go index f9d5f5d4f..48e65f6fe 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -74,6 +74,7 @@ func (c *DockerDriverConfig) Validate() error { } type dockerPID struct { + Version string ImageID string ContainerID string KillTimeout time.Duration @@ -89,6 +90,7 @@ type DockerHandle struct { cleanupImage bool imageID string containerID string + version string killTimeout time.Duration waitCh chan *cstructs.WaitResult doneCh chan struct{} @@ -605,6 +607,7 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle logger: d.logger, imageID: dockerImage.ID, containerID: container.ID, + version: d.config.Version, killTimeout: d.DriverContext.KillTimeout(task), doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -672,6 +675,7 @@ func (d *DockerDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, er logger: d.logger, imageID: pid.ImageID, containerID: pid.ContainerID, + version: pid.Version, killTimeout: pid.KillTimeout, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -683,6 +687,7 @@ func (d *DockerDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, er func (h *DockerHandle) ID() string { // Return a handle to the PID pid := dockerPID{ + Version: h.version, ImageID: h.imageID, ContainerID: h.containerID, KillTimeout: h.killTimeout, diff --git a/client/driver/exec.go b/client/driver/exec.go index 1fe7642d0..e224c4002 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -45,6 +45,7 @@ type execHandle struct { logger *log.Logger waitCh chan *cstructs.WaitResult doneCh chan struct{} + version string } // NewExecDriver is used to create a new exec driver @@ -141,6 +142,7 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, isolationConfig: ps.IsolationConfig, killTimeout: d.DriverContext.KillTimeout(task), logger: d.logger, + version: d.config.Version, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), } @@ -149,6 +151,7 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, } type execId struct { + Version string KillTimeout time.Duration UserPid int TaskDir string @@ -193,6 +196,7 @@ func (d *ExecDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro allocDir: id.AllocDir, isolationConfig: id.IsolationConfig, logger: d.logger, + version: id.Version, killTimeout: id.KillTimeout, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -203,6 +207,7 @@ func (d *ExecDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro func (h *execHandle) ID() string { id := execId{ + Version: h.version, KillTimeout: h.killTimeout, PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, diff --git a/client/driver/java.go b/client/driver/java.go index efab1e170..b9908356b 100644 --- a/client/driver/java.go +++ b/client/driver/java.go @@ -50,6 +50,7 @@ type javaHandle struct { taskDir string allocDir *allocdir.AllocDir killTimeout time.Duration + version string logger *log.Logger waitCh chan *cstructs.WaitResult doneCh chan struct{} @@ -189,6 +190,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, taskDir: taskDir, allocDir: ctx.AllocDir, killTimeout: d.DriverContext.KillTimeout(task), + version: d.config.Version, logger: d.logger, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -206,6 +208,7 @@ func (d *JavaDriver) cgroupsMounted(node *structs.Node) bool { } type javaId struct { + Version string KillTimeout time.Duration PluginConfig *PluginReattachConfig IsolationConfig *cstructs.IsolationConfig @@ -252,6 +255,7 @@ func (d *JavaDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro taskDir: id.TaskDir, allocDir: id.AllocDir, logger: d.logger, + version: id.Version, killTimeout: id.KillTimeout, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -263,6 +267,7 @@ func (d *JavaDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro func (h *javaHandle) ID() string { id := javaId{ + Version: h.version, KillTimeout: h.killTimeout, PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 9dda2feea..1ec44f4f1 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -50,6 +50,7 @@ type qemuHandle struct { allocDir *allocdir.AllocDir killTimeout time.Duration logger *log.Logger + version string waitCh chan *cstructs.WaitResult doneCh chan struct{} } @@ -224,6 +225,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, userPid: ps.Pid, allocDir: ctx.AllocDir, killTimeout: d.DriverContext.KillTimeout(task), + version: d.config.Version, logger: d.logger, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -234,6 +236,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, } type qemuId struct { + Version string KillTimeout time.Duration UserPid int PluginConfig *PluginReattachConfig @@ -267,6 +270,7 @@ func (d *QemuDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro allocDir: id.AllocDir, logger: d.logger, killTimeout: id.KillTimeout, + version: id.Version, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), } @@ -276,6 +280,7 @@ func (d *QemuDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro func (h *qemuHandle) ID() string { id := qemuId{ + Version: h.version, KillTimeout: h.killTimeout, PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, diff --git a/client/driver/raw_exec.go b/client/driver/raw_exec.go index 0938a4645..00cdafc30 100644 --- a/client/driver/raw_exec.go +++ b/client/driver/raw_exec.go @@ -35,6 +35,7 @@ type RawExecDriver struct { // rawExecHandle is returned from Start/Open as a handle to the PID type rawExecHandle struct { + version string pluginClient *plugin.Client userPid int executor executor.Executor @@ -130,6 +131,7 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl userPid: ps.Pid, killTimeout: d.DriverContext.KillTimeout(task), allocDir: ctx.AllocDir, + version: d.config.Version, logger: d.logger, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), @@ -139,6 +141,7 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl } type rawExecId struct { + Version string KillTimeout time.Duration UserPid int PluginConfig *PluginReattachConfig @@ -171,6 +174,7 @@ func (d *RawExecDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, e logger: d.logger, killTimeout: id.KillTimeout, allocDir: id.AllocDir, + version: id.Version, doneCh: make(chan struct{}), waitCh: make(chan *cstructs.WaitResult, 1), } @@ -180,6 +184,7 @@ func (d *RawExecDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, e func (h *rawExecHandle) ID() string { id := rawExecId{ + Version: h.version, KillTimeout: h.killTimeout, PluginConfig: NewPluginReattachConfig(h.pluginClient.ReattachConfig()), UserPid: h.userPid, diff --git a/client/task_runner.go b/client/task_runner.go index b6fb8ce64..e368f7aa0 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -56,6 +56,7 @@ type TaskRunner struct { // taskRunnerState is used to snapshot the state of the task runner type taskRunnerState struct { + Version string Task *structs.Task HandleID string } @@ -153,7 +154,8 @@ func (r *TaskRunner) RestoreState() error { // SaveState is used to snapshot our state func (r *TaskRunner) SaveState() error { snap := taskRunnerState{ - Task: r.task, + Task: r.task, + Version: r.config.Version, } r.handleLock.Lock() if r.handle != nil { diff --git a/command/agent/agent.go b/command/agent/agent.go index b5b6f6837..2293666a3 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -214,6 +214,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port) } conf.Node.HTTPAddr = httpAddr + conf.Version = a.config.Version return conf, nil }