From 03db4cf82d4d5a9bc23595a40c468c0fa486cdf5 Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Fri, 30 Nov 2018 12:18:39 +0100 Subject: [PATCH] client: Rename drivers/shared/env => client/taskenv --- client/allocrunner/interfaces/task_lifecycle.go | 8 ++++---- client/allocrunner/taskrunner/getter/getter.go | 2 +- .../allocrunner/taskrunner/getter/getter_test.go | 6 +++--- client/allocrunner/taskrunner/service_hook.go | 6 +++--- client/allocrunner/taskrunner/task_dir_hook.go | 4 ++-- client/allocrunner/taskrunner/task_runner.go | 6 +++--- client/allocrunner/taskrunner/template/template.go | 4 ++-- .../taskrunner/template/template_test.go | 10 +++++----- client/allocrunner/taskrunner/template_hook.go | 4 ++-- client/allocrunner/taskrunner/validate_hook.go | 4 ++-- .../allocrunner/taskrunner/validate_hook_test.go | 6 +++--- .../taskrunner/consul_template.go | 4 ++-- .../taskrunner/consul_template_test.go | 10 +++++----- .../taskrunner/task_runner.go | 8 ++++---- .../taskrunner/task_runner_test.go | 4 ++-- {drivers/shared/env => client/taskenv}/env.go | 2 +- {drivers/shared/env => client/taskenv}/env_test.go | 14 +++++++------- {drivers/shared/env => client/taskenv}/util.go | 2 +- .../shared/env => client/taskenv}/util_test.go | 2 +- drivers/docker/driver.go | 8 ++++---- drivers/docker/driver_test.go | 4 ++-- drivers/rkt/driver.go | 6 +++--- drivers/rkt/handle.go | 4 ++-- drivers/shared/executor/executor_linux_test.go | 4 ++-- drivers/shared/executor/executor_test.go | 4 ++-- plugins/drivers/testing.go | 4 ++-- plugins/drivers/utils/utils.go | 4 ++-- 27 files changed, 72 insertions(+), 72 deletions(-) rename {drivers/shared/env => client/taskenv}/env.go (99%) rename {drivers/shared/env => client/taskenv}/env_test.go (98%) rename {drivers/shared/env => client/taskenv}/util.go (99%) rename {drivers/shared/env => client/taskenv}/util_test.go (99%) diff --git a/client/allocrunner/interfaces/task_lifecycle.go b/client/allocrunner/interfaces/task_lifecycle.go index 778a5c136..61454f7c8 100644 --- a/client/allocrunner/interfaces/task_lifecycle.go +++ b/client/allocrunner/interfaces/task_lifecycle.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" ) @@ -58,7 +58,7 @@ type TaskPrestartRequest struct { TaskDir *allocdir.TaskDir // TaskEnv is the task's environment - TaskEnv *env.TaskEnv + TaskEnv *taskenv.TaskEnv } type TaskPrestartResponse struct { @@ -99,7 +99,7 @@ type TaskPoststartRequest struct { DriverNetwork *cstructs.DriverNetwork // TaskEnv is the task's environment - TaskEnv *env.TaskEnv + TaskEnv *taskenv.TaskEnv // Stats collector DriverStats DriverStats @@ -141,7 +141,7 @@ type TaskUpdateRequest struct { Alloc *structs.Allocation // TaskEnv is the task's environment - TaskEnv *env.TaskEnv + TaskEnv *taskenv.TaskEnv } type TaskUpdateResponse struct{} diff --git a/client/allocrunner/taskrunner/getter/getter.go b/client/allocrunner/taskrunner/getter/getter.go index 21ed8e8d1..c256990d7 100644 --- a/client/allocrunner/taskrunner/getter/getter.go +++ b/client/allocrunner/taskrunner/getter/getter.go @@ -27,7 +27,7 @@ const ( ) // EnvReplacer is an interface which can interpolate environment variables and -// is usually satisfied by env.TaskEnv. +// is usually satisfied by taskenv.TaskEnv. type EnvReplacer interface { ReplaceEnv(string) string } diff --git a/client/allocrunner/taskrunner/getter/getter_test.go b/client/allocrunner/taskrunner/getter/getter_test.go index 969a880ab..0bb757cdc 100644 --- a/client/allocrunner/taskrunner/getter/getter_test.go +++ b/client/allocrunner/taskrunner/getter/getter_test.go @@ -11,12 +11,12 @@ import ( "strings" "testing" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" ) -// fakeReplacer is a noop version of env.TaskEnv.ReplaceEnv +// fakeReplacer is a noop version of taskenv.TaskEnv.ReplaceEnv type fakeReplacer struct{} func (fakeReplacer) ReplaceEnv(s string) string { @@ -101,7 +101,7 @@ func TestGetGetterUrl_Interpolation(t *testing.T) { alloc := mock.Alloc() task := alloc.Job.TaskGroups[0].Tasks[0] task.Meta = map[string]string{"artifact": url} - taskEnv := env.NewBuilder(mock.Node(), alloc, task, "global").Build() + taskEnv := taskenv.NewBuilder(mock.Node(), alloc, task, "global").Build() act, err := getGetterUrl(taskEnv, artifact) if err != nil { diff --git a/client/allocrunner/taskrunner/service_hook.go b/client/allocrunner/taskrunner/service_hook.go index 86a32d02b..c7feeaa95 100644 --- a/client/allocrunner/taskrunner/service_hook.go +++ b/client/allocrunner/taskrunner/service_hook.go @@ -11,8 +11,8 @@ import ( tinterfaces "github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces" "github.com/hashicorp/nomad/client/consul" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/client/taskenv" agentconsul "github.com/hashicorp/nomad/command/agent/consul" - "github.com/hashicorp/nomad/drivers/shared/env" "github.com/hashicorp/nomad/nomad/structs" ) @@ -41,7 +41,7 @@ type serviceHook struct { canary bool services []*structs.Service networks structs.Networks - taskEnv *env.TaskEnv + taskEnv *taskenv.TaskEnv // Since Update() may be called concurrently with any other hook all // hook methods must be fully serialized @@ -184,7 +184,7 @@ func (h *serviceHook) getTaskServices() *agentconsul.TaskServices { // interpolateServices returns an interpolated copy of services and checks with // values from the task's environment. -func interpolateServices(taskEnv *env.TaskEnv, services []*structs.Service) []*structs.Service { +func interpolateServices(taskEnv *taskenv.TaskEnv, services []*structs.Service) []*structs.Service { interpolated := make([]*structs.Service, len(services)) for i, origService := range services { diff --git a/client/allocrunner/taskrunner/task_dir_hook.go b/client/allocrunner/taskrunner/task_dir_hook.go index 91291d8af..6a09d1e38 100644 --- a/client/allocrunner/taskrunner/task_dir_hook.go +++ b/client/allocrunner/taskrunner/task_dir_hook.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/nomad/client/allocrunner/interfaces" cconfig "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/nomad/structs" ) @@ -54,7 +54,7 @@ func (h *taskDirHook) Prestart(ctx context.Context, req *interfaces.TaskPrestart } // 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 *cconfig.Config) { +func setEnvvars(envBuilder *taskenv.Builder, fsi cstructs.FSIsolation, taskDir *allocdir.TaskDir, conf *cconfig.Config) { // Set driver-specific environment variables switch fsi { case cstructs.FSIsolationNone: diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index 2f0c1dacc..7f2246ac1 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -23,8 +23,8 @@ import ( cinterfaces "github.com/hashicorp/nomad/client/interfaces" cstate "github.com/hashicorp/nomad/client/state" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/client/vaultclient" - "github.com/hashicorp/nomad/drivers/shared/env" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" @@ -133,7 +133,7 @@ type TaskRunner struct { taskDir *allocdir.TaskDir // envBuilder is used to build the task's environment - envBuilder *env.Builder + envBuilder *taskenv.Builder // restartTracker is used to decide if the task should be restarted. restartTracker *restarts.RestartTracker @@ -219,7 +219,7 @@ func NewTaskRunner(config *Config) (*TaskRunner, error) { killCtx, killCancel := context.WithCancel(context.Background()) // Initialize the environment builder - envBuilder := env.NewBuilder( + envBuilder := taskenv.NewBuilder( config.ClientConfig.Node, config.Alloc, config.Task, diff --git a/client/allocrunner/taskrunner/template/template.go b/client/allocrunner/taskrunner/template/template.go index b56da3f98..dfaebeb89 100644 --- a/client/allocrunner/taskrunner/template/template.go +++ b/client/allocrunner/taskrunner/template/template.go @@ -19,7 +19,7 @@ import ( multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" ) @@ -91,7 +91,7 @@ type TaskTemplateManagerConfig struct { TaskDir string // EnvBuilder is the environment variable builder for the task. - EnvBuilder *env.Builder + EnvBuilder *taskenv.Builder // MaxTemplateEventRate is the maximum rate at which we should emit events. MaxTemplateEventRate time.Duration diff --git a/client/allocrunner/taskrunner/template/template_test.go b/client/allocrunner/taskrunner/template/template_test.go index 8201e8bf6..8f4b9ae5c 100644 --- a/client/allocrunner/taskrunner/template/template_test.go +++ b/client/allocrunner/taskrunner/template/template_test.go @@ -13,7 +13,7 @@ import ( ctestutil "github.com/hashicorp/consul/testutil" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -102,7 +102,7 @@ type testHarness struct { manager *TaskTemplateManager mockHooks *MockTaskHooks templates []*structs.Template - envBuilder *env.Builder + envBuilder *taskenv.Builder node *structs.Node config *config.Config vaultToken string @@ -128,7 +128,7 @@ func newTestHarness(t *testing.T, templates []*structs.Template, consul, vault b a := mock.Alloc() task := a.Job.TaskGroups[0].Tasks[0] task.Name = TestTaskName - harness.envBuilder = env.NewBuilder(harness.node, a, task, region) + harness.envBuilder = taskenv.NewBuilder(harness.node, a, task, region) // Make a tempdir d, err := ioutil.TempDir("", "ct_test") @@ -206,7 +206,7 @@ func TestTaskTemplateManager_InvalidConfig(t *testing.T) { clientConfig := &config.Config{Region: "global"} taskDir := "foo" a := mock.Alloc() - envBuilder := env.NewBuilder(mock.Node(), a, a.Job.TaskGroups[0].Tasks[0], clientConfig.Region) + envBuilder := taskenv.NewBuilder(mock.Node(), a, a.Job.TaskGroups[0].Tasks[0], clientConfig.Region) cases := []struct { name string @@ -1277,7 +1277,7 @@ func TestTaskTemplateManager_Config_VaultGrace(t *testing.T) { VaultGrace: 100 * time.Second, }, }, - EnvBuilder: env.NewBuilder(c.Node, alloc, alloc.Job.TaskGroups[0].Tasks[0], c.Region), + EnvBuilder: taskenv.NewBuilder(c.Node, alloc, alloc.Job.TaskGroups[0].Tasks[0], c.Region), } ctmplMapping, err := parseTemplateConfigs(config) diff --git a/client/allocrunner/taskrunner/template_hook.go b/client/allocrunner/taskrunner/template_hook.go index 0db1f60c3..1c76d1447 100644 --- a/client/allocrunner/taskrunner/template_hook.go +++ b/client/allocrunner/taskrunner/template_hook.go @@ -10,7 +10,7 @@ import ( ti "github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces" "github.com/hashicorp/nomad/client/allocrunner/taskrunner/template" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/nomad/structs" ) @@ -31,7 +31,7 @@ type templateHookConfig struct { clientConfig *config.Config // envBuilder is the environment variable builder for the task. - envBuilder *env.Builder + envBuilder *taskenv.Builder } type templateHook struct { diff --git a/client/allocrunner/taskrunner/validate_hook.go b/client/allocrunner/taskrunner/validate_hook.go index daf188d0b..418f9084b 100644 --- a/client/allocrunner/taskrunner/validate_hook.go +++ b/client/allocrunner/taskrunner/validate_hook.go @@ -8,7 +8,7 @@ import ( multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/client/allocrunner/interfaces" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/nomad/structs" ) @@ -39,7 +39,7 @@ func (h *validateHook) Prestart(ctx context.Context, req *interfaces.TaskPrestar return nil } -func validateTask(task *structs.Task, taskEnv *env.TaskEnv, conf *config.Config) error { +func validateTask(task *structs.Task, taskEnv *taskenv.TaskEnv, conf *config.Config) error { var mErr multierror.Error // Validate the user diff --git a/client/allocrunner/taskrunner/validate_hook_test.go b/client/allocrunner/taskrunner/validate_hook_test.go index 1ac9370c5..e71301456 100644 --- a/client/allocrunner/taskrunner/validate_hook_test.go +++ b/client/allocrunner/taskrunner/validate_hook_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/nomad/structs" "github.com/stretchr/testify/require" ) @@ -12,7 +12,7 @@ import ( func TestTaskRunner_Validate_UserEnforcement(t *testing.T) { t.Parallel() - taskEnv := env.NewEmptyBuilder().Build() + taskEnv := taskenv.NewEmptyBuilder().Build() conf := config.DefaultConfig() // Try to run as root with exec. @@ -37,7 +37,7 @@ func TestTaskRunner_Validate_UserEnforcement(t *testing.T) { func TestTaskRunner_Validate_ServiceName(t *testing.T) { t.Parallel() - builder := env.NewEmptyBuilder() + builder := taskenv.NewEmptyBuilder() conf := config.DefaultConfig() // Create a task with a service for validation diff --git a/client/allocrunnerdeprecated/taskrunner/consul_template.go b/client/allocrunnerdeprecated/taskrunner/consul_template.go index 32e000fb6..4bdcb16e9 100644 --- a/client/allocrunnerdeprecated/taskrunner/consul_template.go +++ b/client/allocrunnerdeprecated/taskrunner/consul_template.go @@ -19,7 +19,7 @@ import ( envparse "github.com/hashicorp/go-envparse" multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" ) @@ -105,7 +105,7 @@ type TaskTemplateManagerConfig struct { TaskDir string // EnvBuilder is the environment variable builder for the task. - EnvBuilder *env.Builder + EnvBuilder *taskenv.Builder // MaxTemplateEventRate is the maximum rate at which we should emit events. MaxTemplateEventRate time.Duration diff --git a/client/allocrunnerdeprecated/taskrunner/consul_template_test.go b/client/allocrunnerdeprecated/taskrunner/consul_template_test.go index e10bd7999..6e35d5af9 100644 --- a/client/allocrunnerdeprecated/taskrunner/consul_template_test.go +++ b/client/allocrunnerdeprecated/taskrunner/consul_template_test.go @@ -14,7 +14,7 @@ import ( ctestutil "github.com/hashicorp/consul/testutil" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -108,7 +108,7 @@ type testHarness struct { manager *TaskTemplateManager mockHooks *MockTaskHooks templates []*structs.Template - envBuilder *env.Builder + envBuilder *taskenv.Builder node *structs.Node config *config.Config vaultToken string @@ -134,7 +134,7 @@ func newTestHarness(t *testing.T, templates []*structs.Template, consul, vault b a := mock.Alloc() task := a.Job.TaskGroups[0].Tasks[0] task.Name = TestTaskName - harness.envBuilder = env.NewBuilder(harness.node, a, task, region) + harness.envBuilder = taskenv.NewBuilder(harness.node, a, task, region) // Make a tempdir d, err := ioutil.TempDir("", "ct_test") @@ -210,7 +210,7 @@ func TestTaskTemplateManager_InvalidConfig(t *testing.T) { clientConfig := &config.Config{Region: "global"} taskDir := "foo" a := mock.Alloc() - envBuilder := env.NewBuilder(mock.Node(), a, a.Job.TaskGroups[0].Tasks[0], clientConfig.Region) + envBuilder := taskenv.NewBuilder(mock.Node(), a, a.Job.TaskGroups[0].Tasks[0], clientConfig.Region) cases := []struct { name string @@ -1254,7 +1254,7 @@ func TestTaskTemplateManager_Config_VaultGrace(t *testing.T) { VaultGrace: 100 * time.Second, }, }, - EnvBuilder: env.NewBuilder(c.Node, alloc, alloc.Job.TaskGroups[0].Tasks[0], c.Region), + EnvBuilder: taskenv.NewBuilder(c.Node, alloc, alloc.Job.TaskGroups[0].Tasks[0], c.Region), } ctmplMapping, err := parseTemplateConfigs(config) diff --git a/client/allocrunnerdeprecated/taskrunner/task_runner.go b/client/allocrunnerdeprecated/taskrunner/task_runner.go index 6d6e7852a..8e666683e 100644 --- a/client/allocrunnerdeprecated/taskrunner/task_runner.go +++ b/client/allocrunnerdeprecated/taskrunner/task_runner.go @@ -34,7 +34,7 @@ import ( dstructs "github.com/hashicorp/nomad/client/driver/structs" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" ) const ( @@ -107,7 +107,7 @@ type TaskRunner struct { taskDir *allocdir.TaskDir // envBuilder is used to build the task's environment - envBuilder *env.Builder + envBuilder *taskenv.Builder // driverNet is the network information returned by the driver driverNet *cstructs.DriverNetwork @@ -248,7 +248,7 @@ func NewTaskRunner(logger *log.Logger, config *config.Config, restartTracker := restarts.NewRestartTracker(tg.RestartPolicy, alloc.Job.Type) // Initialize the environment builder - envBuilder := env.NewBuilder(config.Node, alloc, task, config.Region) + envBuilder := taskenv.NewBuilder(config.Node, alloc, task, config.Region) tc := &TaskRunner{ config: config, @@ -1514,7 +1514,7 @@ func (r *TaskRunner) registerServices(d driver.Driver, h driver.DriverHandle, n // interpolateServices interpolates tags in a service and checks with values from the // task's environment. -func interpolateServices(taskEnv *env.TaskEnv, task *structs.Task) *structs.Task { +func interpolateServices(taskEnv *taskenv.TaskEnv, task *structs.Task) *structs.Task { taskCopy := task.Copy() for _, service := range taskCopy.Services { for _, check := range service.Checks { diff --git a/client/allocrunnerdeprecated/taskrunner/task_runner_test.go b/client/allocrunnerdeprecated/taskrunner/task_runner_test.go index 77325cccc..3f39329df 100644 --- a/client/allocrunnerdeprecated/taskrunner/task_runner_test.go +++ b/client/allocrunnerdeprecated/taskrunner/task_runner_test.go @@ -22,9 +22,9 @@ import ( "github.com/hashicorp/nomad/client/config" consulApi "github.com/hashicorp/nomad/client/consul" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/client/vaultclient" "github.com/hashicorp/nomad/command/agent/consul" - "github.com/hashicorp/nomad/drivers/shared/env" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -1695,7 +1695,7 @@ func TestTaskRunner_interpolateServices(t *testing.T) { }, } - env := &env.TaskEnv{ + env := &taskenv.TaskEnv{ EnvMap: map[string]string{ "name": "name", "portlabel": "portlabel", diff --git a/drivers/shared/env/env.go b/client/taskenv/env.go similarity index 99% rename from drivers/shared/env/env.go rename to client/taskenv/env.go index e29c3c8b3..102fd652a 100644 --- a/drivers/shared/env/env.go +++ b/client/taskenv/env.go @@ -1,4 +1,4 @@ -package env +package taskenv import ( "fmt" diff --git a/drivers/shared/env/env_test.go b/client/taskenv/env_test.go similarity index 98% rename from drivers/shared/env/env_test.go rename to client/taskenv/env_test.go index 9d035d194..20841e523 100644 --- a/drivers/shared/env/env_test.go +++ b/client/taskenv/env_test.go @@ -1,4 +1,4 @@ -package env +package taskenv import ( "fmt" @@ -613,7 +613,7 @@ func TestEnvironment_UpdateTask(t *testing.T) { a.Job.TaskGroups[0].Meta = map[string]string{"tgmeta": "tgmetaval"} task := a.Job.TaskGroups[0].Tasks[0] task.Name = "orig" - task.Env = map[string]string{"taskenv": "taskenvval"} + task.Env = map[string]string{"env": "envval"} task.Meta = map[string]string{"taskmeta": "taskmetaval"} builder := NewBuilder(mock.Node(), a, task, "global") @@ -624,8 +624,8 @@ func TestEnvironment_UpdateTask(t *testing.T) { if origMap["NOMAD_META_taskmeta"] != "taskmetaval" { t.Errorf("Expected NOMAD_META_taskmeta=taskmetaval but found %q", origMap["NOMAD_META_taskmeta"]) } - if origMap["taskenv"] != "taskenvval" { - t.Errorf("Expected taskenv=taskenvva but found %q", origMap["taskenv"]) + if origMap["env"] != "envval" { + t.Errorf("Expected env=envva but found %q", origMap["env"]) } if origMap["NOMAD_META_tgmeta"] != "tgmetaval" { t.Errorf("Expected NOMAD_META_tgmeta=tgmetaval but found %q", origMap["NOMAD_META_tgmeta"]) @@ -633,7 +633,7 @@ func TestEnvironment_UpdateTask(t *testing.T) { a.Job.TaskGroups[0].Meta = map[string]string{"tgmeta2": "tgmetaval2"} task.Name = "new" - task.Env = map[string]string{"taskenv2": "taskenvval2"} + task.Env = map[string]string{"env2": "envval2"} task.Meta = map[string]string{"taskmeta2": "taskmetaval2"} newMap := builder.UpdateTask(a, task).Build().Map() @@ -643,8 +643,8 @@ func TestEnvironment_UpdateTask(t *testing.T) { if newMap["NOMAD_META_taskmeta2"] != "taskmetaval2" { t.Errorf("Expected NOMAD_META_taskmeta=taskmetaval but found %q", newMap["NOMAD_META_taskmeta2"]) } - if newMap["taskenv2"] != "taskenvval2" { - t.Errorf("Expected taskenv=taskenvva but found %q", newMap["taskenv2"]) + if newMap["env2"] != "envval2" { + t.Errorf("Expected env=envva but found %q", newMap["env2"]) } if newMap["NOMAD_META_tgmeta2"] != "tgmetaval2" { t.Errorf("Expected NOMAD_META_tgmeta=tgmetaval but found %q", newMap["NOMAD_META_tgmeta2"]) diff --git a/drivers/shared/env/util.go b/client/taskenv/util.go similarity index 99% rename from drivers/shared/env/util.go rename to client/taskenv/util.go index 319b3b797..561b03709 100644 --- a/drivers/shared/env/util.go +++ b/client/taskenv/util.go @@ -1,4 +1,4 @@ -package env +package taskenv import ( "errors" diff --git a/drivers/shared/env/util_test.go b/client/taskenv/util_test.go similarity index 99% rename from drivers/shared/env/util_test.go rename to client/taskenv/util_test.go index 5f93f82a1..c9246713a 100644 --- a/drivers/shared/env/util_test.go +++ b/client/taskenv/util_test.go @@ -1,4 +1,4 @@ -package env +package taskenv import ( "fmt" diff --git a/drivers/docker/driver.go b/drivers/docker/driver.go index 2617254de..da728b13e 100644 --- a/drivers/docker/driver.go +++ b/drivers/docker/driver.go @@ -17,8 +17,8 @@ import ( hclog "github.com/hashicorp/go-hclog" multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/drivers/docker/docklog" - "github.com/hashicorp/nomad/drivers/shared/env" "github.com/hashicorp/nomad/drivers/shared/eventer" nstructs "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" @@ -536,9 +536,9 @@ func (d *Driver) loadImage(task *drivers.TaskConfig, driverConfig *TaskConfig, c func (d *Driver) containerBinds(task *drivers.TaskConfig, driverConfig *TaskConfig) ([]string, error) { - allocDirBind := fmt.Sprintf("%s:%s", task.TaskDir().SharedAllocDir, task.Env[env.AllocDir]) - taskLocalBind := fmt.Sprintf("%s:%s", task.TaskDir().LocalDir, task.Env[env.TaskLocalDir]) - secretDirBind := fmt.Sprintf("%s:%s", task.TaskDir().SecretsDir, task.Env[env.SecretsDir]) + allocDirBind := fmt.Sprintf("%s:%s", task.TaskDir().SharedAllocDir, task.Env[taskenv.AllocDir]) + taskLocalBind := fmt.Sprintf("%s:%s", task.TaskDir().LocalDir, task.Env[taskenv.TaskLocalDir]) + secretDirBind := fmt.Sprintf("%s:%s", task.TaskDir().SecretsDir, task.Env[taskenv.SecretsDir]) binds := []string{allocDirBind, taskLocalBind, secretDirBind} if !d.config.Volumes.Enabled && driverConfig.VolumeDriver != "" { diff --git a/drivers/docker/driver_test.go b/drivers/docker/driver_test.go index e7fc4f5b3..8da95cc5f 100644 --- a/drivers/docker/driver_test.go +++ b/drivers/docker/driver_test.go @@ -20,8 +20,8 @@ import ( "github.com/hashicorp/consul/lib/freeport" hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/client/allocdir" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/client/testutil" - "github.com/hashicorp/nomad/drivers/shared/env" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" @@ -572,7 +572,7 @@ func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) { Args: []string{ "-c", fmt.Sprintf(`sleep 1; echo -n %s > $%s/%s`, - string(exp), env.AllocDir, file), + string(exp), taskenv.AllocDir, file), }, } task := &drivers.TaskConfig{ diff --git a/drivers/rkt/driver.go b/drivers/rkt/driver.go index 8a137d510..b14c2da87 100644 --- a/drivers/rkt/driver.go +++ b/drivers/rkt/driver.go @@ -26,7 +26,7 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/plugins/base" @@ -353,7 +353,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { // The taskConfig's environment is set via --set-env flags in Start, but the rkt // command itself needs an environment with PATH set to find iptables. // TODO (preetha) need to figure out how to read env.blacklist - eb := env.NewEmptyBuilder() + eb := taskenv.NewEmptyBuilder() filter := strings.Split(config.DefaultEnvBlacklist, ",") rktEnv := eb.SetHostEnvvars(filter).Build() @@ -636,7 +636,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru // command itself needs an environment with PATH set to find iptables. // TODO (preetha) need to figure out how to pass env.blacklist from client config - eb := env.NewEmptyBuilder() + eb := taskenv.NewEmptyBuilder() filter := strings.Split(config.DefaultEnvBlacklist, ",") rktEnv := eb.SetHostEnvvars(filter).Build() diff --git a/drivers/rkt/handle.go b/drivers/rkt/handle.go index 4f3f52983..a66e57b26 100644 --- a/drivers/rkt/handle.go +++ b/drivers/rkt/handle.go @@ -9,14 +9,14 @@ import ( hclog "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/plugins/drivers" ) type taskHandle struct { exec executor.Executor - env *env.TaskEnv + env *taskenv.TaskEnv uuid string pid int pluginClient *plugin.Client diff --git a/drivers/shared/executor/executor_linux_test.go b/drivers/shared/executor/executor_linux_test.go index 5656f8568..de7bf54f4 100644 --- a/drivers/shared/executor/executor_linux_test.go +++ b/drivers/shared/executor/executor_linux_test.go @@ -13,8 +13,8 @@ import ( hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/client/allocdir" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/client/testutil" - "github.com/hashicorp/nomad/drivers/shared/env" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" tu "github.com/hashicorp/nomad/testutil" @@ -50,7 +50,7 @@ func testExecutorCommandWithChroot(t *testing.T) (*ExecCommand, *allocdir.AllocD alloc := mock.Alloc() task := alloc.Job.TaskGroups[0].Tasks[0] - taskEnv := env.NewBuilder(mock.Node(), alloc, task, "global").Build() + taskEnv := taskenv.NewBuilder(mock.Node(), alloc, task, "global").Build() allocDir := allocdir.NewAllocDir(testlog.HCLogger(t), filepath.Join(os.TempDir(), alloc.ID)) if err := allocDir.Build(); err != nil { diff --git a/drivers/shared/executor/executor_test.go b/drivers/shared/executor/executor_test.go index 09cb997be..1c274a382 100644 --- a/drivers/shared/executor/executor_test.go +++ b/drivers/shared/executor/executor_test.go @@ -16,7 +16,7 @@ import ( hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/client/allocdir" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" "github.com/stretchr/testify/require" @@ -37,7 +37,7 @@ func init() { func testExecutorCommand(t *testing.T) (*ExecCommand, *allocdir.AllocDir) { alloc := mock.Alloc() task := alloc.Job.TaskGroups[0].Tasks[0] - taskEnv := env.NewBuilder(mock.Node(), alloc, task, "global").Build() + taskEnv := taskenv.NewBuilder(mock.Node(), alloc, task, "global").Build() allocDir := allocdir.NewAllocDir(testlog.HCLogger(t), filepath.Join(os.TempDir(), alloc.ID)) if err := allocDir.Build(); err != nil { diff --git a/plugins/drivers/testing.go b/plugins/drivers/testing.go index 4f9e1caff..eb49ab9e9 100644 --- a/plugins/drivers/testing.go +++ b/plugins/drivers/testing.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/logmon" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" @@ -112,7 +112,7 @@ func (h *DriverHarness) MkAllocDir(t *TaskConfig, enableLogs bool) func() { if t.Resources != nil { task.Resources = t.Resources.NomadResources } - taskBuilder := env.NewBuilder(mock.Node(), mock.Alloc(), task, "global") + taskBuilder := taskenv.NewBuilder(mock.Node(), mock.Alloc(), task, "global") utils.SetEnvvars(taskBuilder, fsi, taskDir, config.DefaultConfig()) taskEnv := taskBuilder.Build() diff --git a/plugins/drivers/utils/utils.go b/plugins/drivers/utils/utils.go index 41a62a2b1..c11fd2a8b 100644 --- a/plugins/drivers/utils/utils.go +++ b/plugins/drivers/utils/utils.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/drivers/shared/env" + "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/discover" "github.com/hashicorp/nomad/nomad/structs" @@ -32,7 +32,7 @@ const ( ) // 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) { +func SetEnvvars(envBuilder *taskenv.Builder, fsi cstructs.FSIsolation, taskDir *allocdir.TaskDir, conf *config.Config) { // Set driver-specific environment variables switch fsi { case cstructs.FSIsolationNone: