Skip to content

Commit

Permalink
client: interpolate driver configurations
Browse files Browse the repository at this point in the history
Also add missing SetDriverNetwork calls.
  • Loading branch information
schmichael committed Nov 6, 2018
1 parent 8122c76 commit d08a3c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ func (tr *TaskRunner) runDriver() error {
// TODO(nickethier): make sure this uses alloc.AllocatedResources once #4750 is rebased
taskConfig := tr.buildTaskConfig()

// TODO: load variables
evalCtx := &hcl.EvalContext{
Variables: tr.envBuilder.Build().AllValues(),
Functions: shared.GetStdlibFuncs(),
}

Expand Down
6 changes: 5 additions & 1 deletion client/allocrunner/taskrunner/task_runner_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ func (tr *TaskRunner) getDriverHandle() *DriverHandle {
return tr.handle
}

// setDriverHanlde sets the driver handle and creates a new result proxy.
// setDriverHanlde sets the driver handle, creates a new result proxy, and
// updates the driver network in the task's environment.
func (tr *TaskRunner) setDriverHandle(handle *DriverHandle) {
tr.handleLock.Lock()
defer tr.handleLock.Unlock()
tr.handle = handle

// Update the environment's driver network
tr.envBuilder.SetDriverNetwork(handle.net)
}

func (tr *TaskRunner) clearDriverHandle() {
Expand Down
15 changes: 15 additions & 0 deletions client/driver/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/nomad/helper"
hargs "github.com/hashicorp/nomad/helper/args"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/zclconf/go-cty/cty"
)

// A set of environment variables that are exported by each driver.
Expand Down Expand Up @@ -159,6 +160,20 @@ func (t *TaskEnv) All() map[string]string {
return m
}

// AllValues is a map of the task's environment variables and the node's
// attributes with cty.Value (String) values.
func (t *TaskEnv) AllValues() map[string]cty.Value {
m := make(map[string]cty.Value, len(t.EnvMap)+len(t.NodeAttrs))
for k, v := range t.EnvMap {
m[k] = cty.StringVal(v)
}
for k, v := range t.NodeAttrs {
m[k] = cty.StringVal(v)
}

return m
}

// ParseAndReplace takes the user supplied args replaces any instance of an
// environment variable or Nomad variable in the args with the actual value.
func (t *TaskEnv) ParseAndReplace(args []string) []string {
Expand Down

0 comments on commit d08a3c8

Please sign in to comment.