Skip to content

Commit

Permalink
client: interpolate meta blocks with task environment (#10876)
Browse files Browse the repository at this point in the history
Adds missing interpolation step to the `meta` blocks when building the task
environment. Also fixes incorrect parameter order in the test assertion and
adds diagnostics to the test.
  • Loading branch information
tgross authored Jul 8, 2021
1 parent 0e49f0d commit d0fb5c8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/10876.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: Fixed bug where meta blocks were not interpolated with task environment
```
4 changes: 2 additions & 2 deletions client/taskenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ func (b *Builder) buildEnv(allocDir, localDir, secretsDir string,
envMap[VaultNamespace] = b.vaultNamespace
}

// Copy task meta
// Copy and interpolate task meta
for k, v := range b.taskMeta {
envMap[k] = v
envMap[hargs.ReplaceEnv(k, nodeAttrs, envMap)] = hargs.ReplaceEnv(v, nodeAttrs, envMap)
}

// Interpolate and add environment variables
Expand Down
8 changes: 7 additions & 1 deletion client/taskenv/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ func TestEnvironment_AllValues(t *testing.T) {
"b.": "b",
".": "c",
}
task.Meta = map[string]string{
"taskMetaKey-${NOMAD_TASK_NAME}": "taskMetaVal-${node.unique.id}",
"foo": "bar",
}
env := NewBuilder(n, a, task, "global").SetDriverNetwork(
&drivers.DriverNetwork{PortMap: map[string]int{"https": 443}},
)
Expand Down Expand Up @@ -361,6 +365,7 @@ func TestEnvironment_AllValues(t *testing.T) {
"NOMAD_META_elb_check_type": "http",
"NOMAD_META_foo": "bar",
"NOMAD_META_owner": "armon",
"NOMAD_META_taskMetaKey_web": "taskMetaVal-" + n.ID,
"NOMAD_JOB_ID": a.Job.ID,
"NOMAD_JOB_NAME": "my-job",
"NOMAD_JOB_PARENT_ID": a.Job.ParentID,
Expand Down Expand Up @@ -405,7 +410,8 @@ func TestEnvironment_AllValues(t *testing.T) {
out := ""
diag = gohcl.DecodeExpression(expr, evalCtx, &out)
require.Empty(t, diag)
require.Equal(t, out, expectedVal)
require.Equal(t, expectedVal, out,
fmt.Sprintf("expected %q got %q", expectedVal, out))
})
}
}
Expand Down

0 comments on commit d0fb5c8

Please sign in to comment.