Skip to content

Commit

Permalink
Append host env vars on every task env
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Dec 20, 2016
1 parent 6702813 commit aaa70ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 7 additions & 1 deletion client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path/filepath"
"strings"

"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/config"
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 0 additions & 5 deletions client/driver/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit aaa70ab

Please sign in to comment.