From aaa70ab7b80645de41a9465198fde2cbae69751d Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 20 Dec 2016 12:24:24 -0800 Subject: [PATCH] Append host env vars on every task env --- client/driver/driver.go | 8 +++++++- client/driver/exec.go | 5 ----- client/task_runner.go | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/driver/driver.go b/client/driver/driver.go index 5d45ca4c814..4060fee5645 100644 --- a/client/driver/driver.go +++ b/client/driver/driver.go @@ -5,6 +5,7 @@ import ( "log" "os" "path/filepath" + "strings" "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" @@ -152,7 +153,8 @@ func NewExecContext(alloc *allocdir.AllocDir, allocID string) *ExecContext { // GetTaskEnv converts the alloc dir, the node, task and alloc into a // TaskEnvironment. func GetTaskEnv(allocDir *allocdir.AllocDir, node *structs.Node, - task *structs.Task, alloc *structs.Allocation, vaultToken string) (*env.TaskEnvironment, error) { + task *structs.Task, alloc *structs.Allocation, conf *config.Config, + vaultToken string) (*env.TaskEnvironment, error) { tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup) env := env.NewTaskEnvironment(node). @@ -188,6 +190,10 @@ func GetTaskEnv(allocDir *allocdir.AllocDir, node *structs.Node, env.SetVaultToken(vaultToken, task.Vault.Env) } + // Set the host environment variables. + filter := strings.Split(conf.ReadDefault("env.blacklist", config.DefaultEnvBlacklist), ",") + env.AppendHostEnvvars(filter) + return env.Build(), nil } diff --git a/client/driver/exec.go b/client/driver/exec.go index 2bc39f11345..1e99e885f64 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -7,13 +7,11 @@ import ( "os" "os/exec" "path/filepath" - "strings" "time" "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/allocdir" - "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/driver/executor" dstructs "github.com/hashicorp/nomad/client/driver/structs" cstructs "github.com/hashicorp/nomad/client/structs" @@ -93,9 +91,6 @@ func (d *ExecDriver) Periodic() (bool, time.Duration) { } func (d *ExecDriver) Prestart(execctx *ExecContext, task *structs.Task) error { - // Set the host environment variables. - filter := strings.Split(d.config.ReadDefault("env.blacklist", config.DefaultEnvBlacklist), ",") - d.taskEnv.AppendHostEnvvars(filter) return nil } diff --git a/client/task_runner.go b/client/task_runner.go index 46b47c1d066..1d1e297a1a2 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -324,7 +324,8 @@ func (r *TaskRunner) setTaskEnv() error { r.taskEnvLock.Lock() defer r.taskEnvLock.Unlock() - taskEnv, err := driver.GetTaskEnv(r.ctx.AllocDir, r.config.Node, r.task.Copy(), r.alloc, r.vaultFuture.Get()) + taskEnv, err := driver.GetTaskEnv(r.ctx.AllocDir, r.config.Node, + r.task.Copy(), r.alloc, r.config, r.vaultFuture.Get()) if err != nil { return err }