From ff0dd9b81ce20aa6ad40cb105382315a69f071e0 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 25 Apr 2016 17:20:25 -0700 Subject: [PATCH] Task is not eligible for update if User, Meta, or Resources change --- nomad/mock/mock.go | 3 +++ scheduler/util.go | 21 +++++++++------------ scheduler/util_test.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/nomad/mock/mock.go b/nomad/mock/mock.go index 3eed7dd75..9e9208641 100644 --- a/nomad/mock/mock.go +++ b/nomad/mock/mock.go @@ -127,6 +127,9 @@ func Job() *structs.Job { }, }, }, + Meta: map[string]string{ + "foo": "bar", + }, }, }, Meta: map[string]string{ diff --git a/scheduler/util.go b/scheduler/util.go index 382573871..794fca3ba 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -293,27 +293,24 @@ func tasksUpdated(a, b *structs.TaskGroup) bool { if at.Driver != bt.Driver { return true } + if at.User != bt.User { + return true + } if !reflect.DeepEqual(at.Config, bt.Config) { return true } if !reflect.DeepEqual(at.Env, bt.Env) { 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) { 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 } diff --git a/scheduler/util_test.go b/scheduler/util_test.go index bcae1d290..c4fa2fa30 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -376,6 +376,34 @@ func TestTasksUpdated(t *testing.T) { if !tasksUpdated(j1.TaskGroups[0], j7.TaskGroups[0]) { 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) {