Append host env vars on every task env

This commit is contained in:
Michael Schurter
2016-12-20 12:24:24 -08:00
parent 6702813233
commit aaa70ab7b8
3 changed files with 9 additions and 7 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}