From 2d33d48980ad53787e5185de72ec20e2be2bbd92 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 5 Dec 2018 11:04:18 -0500 Subject: [PATCH] executor: update driver references --- drivers/exec/driver.go | 10 +++++----- drivers/exec/handle.go | 7 ++++--- drivers/java/driver.go | 8 ++++---- drivers/java/handle.go | 7 ++++--- drivers/qemu/driver.go | 6 +++--- drivers/qemu/handle.go | 7 ++++--- drivers/rawexec/driver.go | 6 +++--- drivers/rawexec/handle.go | 7 ++++--- drivers/rkt/driver.go | 8 ++++---- drivers/rkt/handle.go | 7 ++++--- 10 files changed, 39 insertions(+), 34 deletions(-) diff --git a/drivers/exec/driver.go b/drivers/exec/driver.go index 14eca02c3..7398ee022 100644 --- a/drivers/exec/driver.go +++ b/drivers/exec/driver.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/nomad/client/fingerprint" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/eventer" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" @@ -298,7 +298,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru return nil, nil, fmt.Errorf("failed to create executor: %v", err) } - execCmd := &executor.ExecCommand{ + execCmd := &structs.ExecCommand{ Cmd: driverConfig.Command, Args: driverConfig.Args, Env: cfg.EnvList(), @@ -345,12 +345,12 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru return handle, nil, nil } -func toExecResources(resources *drivers.Resources) *executor.Resources { +func toExecResources(resources *drivers.Resources) *structs.Resources { if resources == nil || resources.NomadResources == nil { return nil } - return &executor.Resources{ + return &structs.Resources{ CPU: resources.NomadResources.CPU, MemoryMB: resources.NomadResources.MemoryMB, DiskMB: resources.NomadResources.DiskMB, @@ -373,7 +373,7 @@ func (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.E func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *drivers.ExitResult) { defer close(ch) var result *drivers.ExitResult - ps, err := handle.exec.Wait() + ps, err := handle.exec.Wait(ctx) if err != nil { result = &drivers.ExitResult{ Err: fmt.Errorf("executor: error waiting on process: %v", err), diff --git a/drivers/exec/handle.go b/drivers/exec/handle.go index 3feb158dc..1c73573ac 100644 --- a/drivers/exec/handle.go +++ b/drivers/exec/handle.go @@ -1,18 +1,19 @@ package exec import ( + "context" "strconv" "sync" "time" hclog "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/drivers" ) type taskHandle struct { - exec executor.Executor + exec structs.Executor pid int pluginClient *plugin.Client logger hclog.Logger @@ -58,7 +59,7 @@ func (h *taskHandle) run() { h.stateLock.Unlock() // Block until process exits - ps, err := h.exec.Wait() + ps, err := h.exec.Wait(context.Background()) h.stateLock.Lock() defer h.stateLock.Unlock() diff --git a/drivers/java/driver.go b/drivers/java/driver.go index a9ac5a0fb..840f99245 100644 --- a/drivers/java/driver.go +++ b/drivers/java/driver.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/nomad/client/fingerprint" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/eventer" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" @@ -330,13 +330,13 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru return nil, nil, fmt.Errorf("failed to create executor: %v", err) } - execCmd := &executor.ExecCommand{ + execCmd := &structs.ExecCommand{ Cmd: absPath, Args: args, Env: cfg.EnvList(), User: cfg.User, ResourceLimits: true, - Resources: &executor.Resources{ + Resources: &structs.Resources{ CPU: cfg.Resources.NomadResources.CPU, MemoryMB: cfg.Resources.NomadResources.MemoryMB, DiskMB: cfg.Resources.NomadResources.DiskMB, @@ -426,7 +426,7 @@ func (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.E func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *drivers.ExitResult) { defer close(ch) var result *drivers.ExitResult - ps, err := handle.exec.Wait() + ps, err := handle.exec.Wait(ctx) if err != nil { result = &drivers.ExitResult{ Err: fmt.Errorf("executor: error waiting on process: %v", err), diff --git a/drivers/java/handle.go b/drivers/java/handle.go index 7d493a4a4..339036612 100644 --- a/drivers/java/handle.go +++ b/drivers/java/handle.go @@ -1,18 +1,19 @@ package java import ( + "context" "strconv" "sync" "time" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/drivers" ) type taskHandle struct { - exec executor.Executor + exec structs.Executor pid int pluginClient *plugin.Client logger hclog.Logger @@ -57,7 +58,7 @@ func (h *taskHandle) run() { } h.stateLock.Unlock() - ps, err := h.exec.Wait() + ps, err := h.exec.Wait(context.Background()) h.stateLock.Lock() defer h.stateLock.Unlock() diff --git a/drivers/qemu/driver.go b/drivers/qemu/driver.go index 2a37aa6b5..1f632e22c 100644 --- a/drivers/qemu/driver.go +++ b/drivers/qemu/driver.go @@ -18,7 +18,7 @@ import ( "github.com/hashicorp/go-plugin" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/eventer" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" @@ -424,7 +424,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru return nil, nil, err } - execCmd := &executor.ExecCommand{ + execCmd := &structs.ExecCommand{ Cmd: args[0], Args: args[1:], Env: cfg.EnvList(), @@ -584,7 +584,7 @@ func GetAbsolutePath(bin string) (string, error) { func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *drivers.ExitResult) { defer close(ch) var result *drivers.ExitResult - ps, err := handle.exec.Wait() + ps, err := handle.exec.Wait(ctx) if err != nil { result = &drivers.ExitResult{ Err: fmt.Errorf("executor: error waiting on process: %v", err), diff --git a/drivers/qemu/handle.go b/drivers/qemu/handle.go index b7aca3614..4f54c22ad 100644 --- a/drivers/qemu/handle.go +++ b/drivers/qemu/handle.go @@ -1,18 +1,19 @@ package qemu import ( + "context" "strconv" "sync" "time" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/drivers" ) type taskHandle struct { - exec executor.Executor + exec structs.Executor pid int pluginClient *plugin.Client logger hclog.Logger @@ -58,7 +59,7 @@ func (h *taskHandle) run() { } h.stateLock.Unlock() - ps, err := h.exec.Wait() + ps, err := h.exec.Wait(context.Background()) h.stateLock.Lock() defer h.stateLock.Unlock() diff --git a/drivers/rawexec/driver.go b/drivers/rawexec/driver.go index e182764ef..78cdad364 100644 --- a/drivers/rawexec/driver.go +++ b/drivers/rawexec/driver.go @@ -15,7 +15,7 @@ import ( plugin "github.com/hashicorp/go-plugin" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/eventer" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" @@ -327,7 +327,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru // will cause an error. useCgroups := !d.config.NoCgroups && runtime.GOOS == "linux" && syscall.Geteuid() == 0 - execCmd := &executor.ExecCommand{ + execCmd := &structs.ExecCommand{ Cmd: driverConfig.Command, Args: driverConfig.Args, Env: cfg.EnvList(), @@ -388,7 +388,7 @@ func (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.E func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *drivers.ExitResult) { defer close(ch) var result *drivers.ExitResult - ps, err := handle.exec.Wait() + ps, err := handle.exec.Wait(ctx) if err != nil { result = &drivers.ExitResult{ Err: fmt.Errorf("executor: error waiting on process: %v", err), diff --git a/drivers/rawexec/handle.go b/drivers/rawexec/handle.go index 28d9129db..72401556a 100644 --- a/drivers/rawexec/handle.go +++ b/drivers/rawexec/handle.go @@ -1,18 +1,19 @@ package rawexec import ( + "context" "strconv" "sync" "time" hclog "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/drivers" ) type taskHandle struct { - exec executor.Executor + exec structs.Executor pid int pluginClient *plugin.Client logger hclog.Logger @@ -58,7 +59,7 @@ func (h *taskHandle) run() { h.stateLock.Unlock() // Block until process exits - ps, err := h.exec.Wait() + ps, err := h.exec.Wait(context.Background()) h.stateLock.Lock() defer h.stateLock.Unlock() diff --git a/drivers/rkt/driver.go b/drivers/rkt/driver.go index b14c2da87..7cab0c8b0 100644 --- a/drivers/rkt/driver.go +++ b/drivers/rkt/driver.go @@ -28,7 +28,7 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/drivers/shared/eventer" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" @@ -643,11 +643,11 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru // Enable ResourceLimits to place the executor in a parent cgroup of // the rkt container. This allows stats collection via the executor to // work just like it does for exec. - execCmd := &executor.ExecCommand{ + execCmd := &structs.ExecCommand{ Cmd: absPath, Args: runArgs, ResourceLimits: true, - Resources: &executor.Resources{ + Resources: &structs.Resources{ CPU: int(cfg.Resources.LinuxResources.CPUShares), MemoryMB: int(drivers.BytesToMB(cfg.Resources.LinuxResources.MemoryLimitBytes)), DiskMB: cfg.Resources.NomadResources.DiskMB, @@ -995,7 +995,7 @@ func elide(inBuf bytes.Buffer) string { func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *drivers.ExitResult) { defer close(ch) var result *drivers.ExitResult - ps, err := handle.exec.Wait() + ps, err := handle.exec.Wait(ctx) if err != nil { result = &drivers.ExitResult{ Err: fmt.Errorf("executor: error waiting on process: %v", err), diff --git a/drivers/rkt/handle.go b/drivers/rkt/handle.go index a66e57b26..d77ae2173 100644 --- a/drivers/rkt/handle.go +++ b/drivers/rkt/handle.go @@ -3,6 +3,7 @@ package rkt import ( + "context" "strconv" "sync" "time" @@ -10,12 +11,12 @@ import ( hclog "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/taskenv" - "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/drivers/shared/executor/structs" "github.com/hashicorp/nomad/plugins/drivers" ) type taskHandle struct { - exec executor.Executor + exec structs.Executor env *taskenv.TaskEnv uuid string pid int @@ -62,7 +63,7 @@ func (h *taskHandle) run() { } h.stateLock.Unlock() - ps, err := h.exec.Wait() + ps, err := h.exec.Wait(context.Background()) h.stateLock.Lock() defer h.stateLock.Unlock()