From 23197ec6b45527c91dd5fcbbd6418ddad122c30d Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Wed, 28 Nov 2018 17:29:57 +0100 Subject: [PATCH] drivers: Create drivers/shared/structs This creates a drivers/shared/structs package and moves the buffer size checks into it. --- drivers/docker/handle.go | 23 ++++++++++++----------- drivers/shared/executor/executor.go | 4 ++-- drivers/shared/executor/executor_linux.go | 2 +- drivers/shared/structs/structs.go | 4 ++++ plugins/drivers/driver.go | 5 ----- 5 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 drivers/shared/structs/structs.go diff --git a/drivers/docker/handle.go b/drivers/docker/handle.go index a49c1844c..e15b542db 100644 --- a/drivers/docker/handle.go +++ b/drivers/docker/handle.go @@ -13,8 +13,9 @@ import ( docker "github.com/fsouza/go-dockerclient" hclog "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/client/structs" + cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/docker/docklog" + dstructs "github.com/hashicorp/nomad/drivers/shared/structs" "github.com/hashicorp/nomad/helper/stats" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/shared" @@ -31,11 +32,11 @@ type taskHandle struct { containerID string containerImage string resourceUsageLock sync.RWMutex - resourceUsage *structs.TaskResourceUsage + resourceUsage *cstructs.TaskResourceUsage doneCh chan bool waitCh chan struct{} removeContainerOnExit bool - net *structs.DriverNetwork + net *cstructs.DriverNetwork exitResult *drivers.ExitResult exitResultLock sync.Mutex @@ -52,7 +53,7 @@ type taskHandleState struct { ReattachConfig *shared.ReattachConfig ContainerID string - DriverNetwork *structs.DriverNetwork + DriverNetwork *cstructs.DriverNetwork } func (h *taskHandle) buildState() *taskHandleState { @@ -82,8 +83,8 @@ func (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*driv } execResult := &drivers.ExecTaskResult{ExitResult: &drivers.ExitResult{}} - stdout, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize)) - stderr, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize)) + stdout, _ := circbuf.NewBuffer(int64(dstructs.CheckBufSize)) + stderr, _ := circbuf.NewBuffer(int64(dstructs.CheckBufSize)) startOpts := docker.StartExecOptions{ Detach: false, Tty: false, @@ -155,7 +156,7 @@ func (h *taskHandle) Kill(killTimeout time.Duration, signal os.Signal) error { return nil } -func (h *taskHandle) Stats() (*structs.TaskResourceUsage, error) { +func (h *taskHandle) Stats() (*cstructs.TaskResourceUsage, error) { h.resourceUsageLock.RLock() defer h.resourceUsageLock.RUnlock() var err error @@ -235,7 +236,7 @@ func (h *taskHandle) collectStats() { select { case s := <-statsCh: if s != nil { - ms := &structs.MemoryStats{ + ms := &cstructs.MemoryStats{ RSS: s.MemoryStats.Stats.Rss, Cache: s.MemoryStats.Stats.Cache, Swap: s.MemoryStats.Stats.Swap, @@ -243,7 +244,7 @@ func (h *taskHandle) collectStats() { Measured: DockerMeasuredMemStats, } - cs := &structs.CpuStats{ + cs := &cstructs.CpuStats{ ThrottledPeriods: s.CPUStats.ThrottlingData.ThrottledPeriods, ThrottledTime: s.CPUStats.ThrottlingData.ThrottledTime, Measured: DockerMeasuredCpuStats, @@ -262,8 +263,8 @@ func (h *taskHandle) collectStats() { cs.TotalTicks = (cs.Percent / 100) * stats.TotalTicksAvailable() / float64(numCores) h.resourceUsageLock.Lock() - h.resourceUsage = &structs.TaskResourceUsage{ - ResourceUsage: &structs.ResourceUsage{ + h.resourceUsage = &cstructs.TaskResourceUsage{ + ResourceUsage: &cstructs.ResourceUsage{ MemoryStats: ms, CpuStats: cs, }, diff --git a/drivers/shared/executor/executor.go b/drivers/shared/executor/executor.go index 5316a27b5..511776368 100644 --- a/drivers/shared/executor/executor.go +++ b/drivers/shared/executor/executor.go @@ -23,8 +23,8 @@ import ( shelpers "github.com/hashicorp/nomad/helper/stats" "github.com/hashicorp/consul-template/signals" - dstructs "github.com/hashicorp/nomad/client/driver/structs" cstructs "github.com/hashicorp/nomad/client/structs" + dstructs "github.com/hashicorp/nomad/drivers/shared/structs" ) const ( @@ -310,7 +310,7 @@ func (e *UniversalExecutor) Exec(deadline time.Time, name string, args []string) } // ExecScript executes cmd with args and returns the output, exit code, and -// error. Output is truncated to client/driver/structs.CheckBufSize +// error. Output is truncated to drivers/shared/structs.CheckBufSize func ExecScript(ctx context.Context, dir string, env []string, attrs *syscall.SysProcAttr, name string, args []string) ([]byte, int, error) { cmd := exec.CommandContext(ctx, name, args...) diff --git a/drivers/shared/executor/executor_linux.go b/drivers/shared/executor/executor_linux.go index be1f76f6d..07b5ee953 100644 --- a/drivers/shared/executor/executor_linux.go +++ b/drivers/shared/executor/executor_linux.go @@ -17,9 +17,9 @@ import ( "github.com/hashicorp/consul-template/signals" hclog "github.com/hashicorp/go-hclog" multierror "github.com/hashicorp/go-multierror" - dstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/client/stats" cstructs "github.com/hashicorp/nomad/client/structs" + dstructs "github.com/hashicorp/nomad/drivers/shared/structs" "github.com/hashicorp/nomad/helper/discover" shelpers "github.com/hashicorp/nomad/helper/stats" "github.com/hashicorp/nomad/helper/uuid" diff --git a/drivers/shared/structs/structs.go b/drivers/shared/structs/structs.go new file mode 100644 index 000000000..733640aa9 --- /dev/null +++ b/drivers/shared/structs/structs.go @@ -0,0 +1,4 @@ +package structs + +// CheckBufSize is the size of the buffer that is used for job output +const CheckBufSize = 4 * 1024 diff --git a/plugins/drivers/driver.go b/plugins/drivers/driver.go index ea9d14bef..a9afc8e19 100644 --- a/plugins/drivers/driver.go +++ b/plugins/drivers/driver.go @@ -18,11 +18,6 @@ import ( "github.com/zclconf/go-cty/cty/msgpack" ) -const ( - // CheckBufSize is the size of the check output result - CheckBufSize = 4 * 1024 -) - // DriverPlugin is the interface with drivers will implement. It is also // implemented by a plugin client which proxies the calls to go-plugin. See // the proto/driver.proto file for detailed information about each RPC and