Skip to content

Commit

Permalink
Merge pull request #327 from hashicorp/b-check-env-var-updates
Browse files Browse the repository at this point in the history
Check for environment variable updates for tasks
  • Loading branch information
armon committed Oct 26, 2015
2 parents 6a8ea07 + 0f5e93e commit 3058ae8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func Job() *structs.Job {
"command": "/bin/date",
"args": "+%s",
},
Env: map[string]string{
"FOO": "bar",
},
Resources: &structs.Resources{
CPU: 500,
MemoryMB: 256,
Expand Down
5 changes: 4 additions & 1 deletion scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func shuffleNodes(nodes []*structs.Node) {
}

// tasksUpdated does a diff between task groups to see if the
// tasks, their drivers or config have updated.
// tasks, their drivers, environment variables or config have updated.
func tasksUpdated(a, b *structs.TaskGroup) bool {
// If the number of tasks do not match, clearly there is an update
if len(a.Tasks) != len(b.Tasks) {
Expand All @@ -282,6 +282,9 @@ func tasksUpdated(a, b *structs.TaskGroup) bool {
if !reflect.DeepEqual(at.Config, bt.Config) {
return true
}
if !reflect.DeepEqual(at.Env, bt.Env) {
return true
}

// Inspect the network to see if the dynamic ports are different
if len(at.Resources.Networks) != len(bt.Resources.Networks) {
Expand Down
6 changes: 6 additions & 0 deletions scheduler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ func TestTasksUpdated(t *testing.T) {
if !tasksUpdated(j1.TaskGroups[0], j6.TaskGroups[0]) {
t.Fatalf("bad")
}

j7 := mock.Job()
j7.TaskGroups[0].Tasks[0].Env["NEW_ENV"] = "NEW_VALUE"
if !tasksUpdated(j1.TaskGroups[0], j7.TaskGroups[0]) {
t.Fatalf("bad")
}
}

func TestEvictAndPlace_LimitLessThanAllocs(t *testing.T) {
Expand Down

0 comments on commit 3058ae8

Please sign in to comment.