Merge pull request #1128 from hashicorp/f-restrict-inplace

Task is not eligible for update if User, Meta, or Resources change
This commit is contained in:
Alex Dadgar 2016-04-26 10:12:42 -07:00
commit 2fb4d1d0cb
3 changed files with 40 additions and 12 deletions

View file

@ -127,6 +127,9 @@ func Job() *structs.Job {
}, },
}, },
}, },
Meta: map[string]string{
"foo": "bar",
},
}, },
}, },
Meta: map[string]string{ Meta: map[string]string{

View file

@ -293,27 +293,24 @@ func tasksUpdated(a, b *structs.TaskGroup) bool {
if at.Driver != bt.Driver { if at.Driver != bt.Driver {
return true return true
} }
if at.User != bt.User {
return true
}
if !reflect.DeepEqual(at.Config, bt.Config) { if !reflect.DeepEqual(at.Config, bt.Config) {
return true return true
} }
if !reflect.DeepEqual(at.Env, bt.Env) { if !reflect.DeepEqual(at.Env, bt.Env) {
return true return true
} }
if !reflect.DeepEqual(at.Resources, bt.Resources) {
return true
}
if !reflect.DeepEqual(at.Meta, bt.Meta) {
return true
}
if !reflect.DeepEqual(at.Artifacts, bt.Artifacts) { if !reflect.DeepEqual(at.Artifacts, bt.Artifacts) {
return true return true
} }
// Inspect the network to see if the dynamic ports are different
if len(at.Resources.Networks) != len(bt.Resources.Networks) {
return true
}
for idx := range at.Resources.Networks {
an := at.Resources.Networks[idx]
bn := bt.Resources.Networks[idx]
if len(an.DynamicPorts) != len(bn.DynamicPorts) {
return true
}
}
} }
return false return false
} }

View file

@ -376,6 +376,34 @@ func TestTasksUpdated(t *testing.T) {
if !tasksUpdated(j1.TaskGroups[0], j7.TaskGroups[0]) { if !tasksUpdated(j1.TaskGroups[0], j7.TaskGroups[0]) {
t.Fatalf("bad") t.Fatalf("bad")
} }
j8 := mock.Job()
j8.TaskGroups[0].Tasks[0].User = "foo"
if !tasksUpdated(j1.TaskGroups[0], j8.TaskGroups[0]) {
t.Fatalf("bad")
}
j9 := mock.Job()
j9.TaskGroups[0].Tasks[0].Artifacts = []*structs.TaskArtifact{
{
GetterSource: "http://foo.com/bar",
},
}
if !tasksUpdated(j1.TaskGroups[0], j9.TaskGroups[0]) {
t.Fatalf("bad")
}
j10 := mock.Job()
j10.TaskGroups[0].Tasks[0].Meta["baz"] = "boom"
if !tasksUpdated(j1.TaskGroups[0], j10.TaskGroups[0]) {
t.Fatalf("bad")
}
j11 := mock.Job()
j11.TaskGroups[0].Tasks[0].Resources.CPU = 1337
if !tasksUpdated(j1.TaskGroups[0], j11.TaskGroups[0]) {
t.Fatalf("bad")
}
} }
func TestEvictAndPlace_LimitLessThanAllocs(t *testing.T) { func TestEvictAndPlace_LimitLessThanAllocs(t *testing.T) {