Skip to content

Commit

Permalink
Revert "client/driver/env: interpolate empty optional meta params as …
Browse files Browse the repository at this point in the history
…empty strings"

This reverts commit 84926f7.
  • Loading branch information
dadgar committed Jun 7, 2018
1 parent 268a776 commit c17e0fc
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 35 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ IMPROVEMENTS:
image pulls [[GH-4192](https://github.com/hashicorp/nomad/issues/4192)]
* driver/raw_exec: Use cgroups to manage process tree for precise cleanup of
launched processes [[GH-4350](https://github.com/hashicorp/nomad/issues/4350)]
* env: Default interpolation of optional meta fields of parameterized jobs to
an empty string rather than the field key. [[GH-3720](https://github.com/hashicorp/nomad/issues/3720)]
* ui: Show node drain, node eligibility, and node drain strategy information in the Client list and Client detail pages [[GH-4353](https://github.com/hashicorp/nomad/issues/4353)]
* ui: Show reschedule-event information for allocations that were server-side rescheduled [[GH-4254](https://github.com/hashicorp/nomad/issues/4254)]
* ui: Show the running deployment Progress Deadlines on the Job Detail Page [[GH-4388](https://github.com/hashicorp/nomad/issues/4388)]
Expand Down
18 changes: 1 addition & 17 deletions client/driver/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,23 +397,7 @@ func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder {

// Set meta
combined := alloc.Job.CombinedTaskMeta(alloc.TaskGroup, b.taskName)
// taskMetaSize is double to total meta keys to account for given and upper
// cased values
taskMetaSize := len(combined) * 2

// if job is parameterized initialize optional meta to empty strings
if alloc.Job.IsParameterized() {
b.taskMeta = make(map[string]string,
taskMetaSize+(len(alloc.Job.ParameterizedJob.MetaOptional)*2))

for _, k := range alloc.Job.ParameterizedJob.MetaOptional {
b.taskMeta[fmt.Sprintf("%s%s", MetaPrefix, strings.ToUpper(k))] = ""
b.taskMeta[fmt.Sprintf("%s%s", MetaPrefix, k)] = ""
}
} else {
b.taskMeta = make(map[string]string, taskMetaSize)
}

b.taskMeta = make(map[string]string, len(combined)*2)
for k, v := range combined {
b.taskMeta[fmt.Sprintf("%s%s", MetaPrefix, strings.ToUpper(k))] = v
b.taskMeta[fmt.Sprintf("%s%s", MetaPrefix, k)] = v
Expand Down
16 changes: 0 additions & 16 deletions client/driver/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -373,18 +372,3 @@ func TestEnvironment_UpdateTask(t *testing.T) {
t.Errorf("Expected NOMAD_META_taskmeta to be unset but found: %q", v)
}
}

// TestEnvironment_InterpolateEmptyOptionalMeta asserts that in a parameterized
// job, if an optional meta field is not set, it will get interpolated as an
// empty string.
func TestEnvironment_InterpolateEmptyOptionalMeta(t *testing.T) {
a := mock.Alloc()
a.Job.ParameterizedJob = &structs.ParameterizedJobConfig{
MetaOptional: []string{"metaopt1", "metaopt2"},
}
task := a.Job.TaskGroups[0].Tasks[0]
task.Meta = map[string]string{"metaopt1": "metaopt1val"}
env := NewBuilder(mock.Node(), a, task, "global").Build()
require.Equal(t, "metaopt1val", env.ReplaceEnv("${NOMAD_META_metaopt1}"))
require.Empty(t, env.ReplaceEnv("${NOMAD_META_metaopt2}"))
}

0 comments on commit c17e0fc

Please sign in to comment.