mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
Append host env vars on every task env
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user