From db31a9cd991a7f6cad79dc802b6ff31375abac68 Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Thu, 29 Nov 2018 14:58:36 +0100 Subject: [PATCH] client/driver: Vendor setEnvvars into docker_test --- client/driver/docker_test.go | 25 ++++++++++++++++++++++++- client/driver/driver_test.go | 4 ++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 44a69ab99..365ad01de 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -1702,6 +1702,29 @@ func TestDockerDriver_Stats(t *testing.T) { } } +// setEnvvars sets path and host env vars depending on the FS isolation used. +func setEnvvars(envBuilder *env.Builder, fsi cstructs.FSIsolation, taskDir *allocdir.TaskDir, conf *config.Config) { + // Set driver-specific environment variables + switch fsi { + case cstructs.FSIsolationNone: + // Use host paths + envBuilder.SetAllocDir(taskDir.SharedAllocDir) + envBuilder.SetTaskLocalDir(taskDir.LocalDir) + envBuilder.SetSecretsDir(taskDir.SecretsDir) + default: + // filesystem isolation; use container paths + envBuilder.SetAllocDir(allocdir.SharedAllocContainerPath) + envBuilder.SetTaskLocalDir(allocdir.TaskLocalContainerPath) + envBuilder.SetSecretsDir(allocdir.TaskSecretsContainerPath) + } + + // Set the host environment variables for non-image based drivers + if fsi != cstructs.FSIsolationImage { + filter := strings.Split(conf.ReadDefault("env.blacklist", config.DefaultEnvBlacklist), ",") + envBuilder.SetHostEnvvars(filter) + } +} + func setupDockerVolumes(t *testing.T, cfg *config.Config, hostpath string) (*structs.Task, Driver, *ExecContext, string, func()) { if !testutil.DockerIsConnected(t) { t.Skip("Docker not connected") @@ -1753,7 +1776,7 @@ func setupDockerVolumes(t *testing.T, cfg *config.Config, hostpath string) (*str // Setup execCtx envBuilder := env.NewBuilder(cfg.Node, alloc, task, cfg.Region) - SetEnvvars(envBuilder, driver.FSIsolation(), taskDir, cfg) + setEnvvars(envBuilder, driver.FSIsolation(), taskDir, cfg) execCtx := NewExecContext(taskDir, envBuilder.Build()) // Setup cleanup function diff --git a/client/driver/driver_test.go b/client/driver/driver_test.go index 1db47f0c4..34cf68b34 100644 --- a/client/driver/driver_test.go +++ b/client/driver/driver_test.go @@ -150,7 +150,7 @@ func testDriverContexts(t *testing.T, task *structs.Task) *testContext { return nil } eb := env.NewBuilder(cfg.Node, alloc, task, cfg.Region) - SetEnvvars(eb, tmpdrv.FSIsolation(), td, cfg) + setEnvvars(eb, tmpdrv.FSIsolation(), td, cfg) execCtx := NewExecContext(td, eb.Build()) logger := testlog.Logger(t) @@ -234,7 +234,7 @@ func setupTaskEnv(t *testing.T, driver string) (*allocdir.TaskDir, map[string]st if err != nil { t.Fatalf("unable to create driver %q: %v", driver, err) } - SetEnvvars(eb, tmpDriver.FSIsolation(), taskDir, conf) + setEnvvars(eb, tmpDriver.FSIsolation(), taskDir, conf) exp := map[string]string{ "NOMAD_CPU_LIMIT": "1000", "NOMAD_MEMORY_LIMIT": "500",