From 65c08b76d3e9ef6ffdc5645a29afa89e9dd9be57 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 5 Jun 2018 13:58:53 -0500 Subject: [PATCH 1/2] Fix reconciler bug with deployment not being created if job create index is different This fixes an issue where if a job is purged and resubmitted Nomad does not create a new deployment. Adds unit test that failed before this fix --- scheduler/reconcile.go | 2 +- scheduler/reconcile_test.go | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/scheduler/reconcile.go b/scheduler/reconcile.go index 63c9cff7286..5538f9500a6 100644 --- a/scheduler/reconcile.go +++ b/scheduler/reconcile.go @@ -500,7 +500,7 @@ func (a *allocReconciler) computeGroup(group string, all allocSet) bool { updatingSpec := len(destructive) != 0 || len(a.result.inplaceUpdate) != 0 hadRunning := false for _, alloc := range all { - if alloc.Job.Version == a.job.Version { + if alloc.Job.Version == a.job.Version && alloc.Job.CreateIndex == a.job.CreateIndex { hadRunning = true break } diff --git a/scheduler/reconcile_test.go b/scheduler/reconcile_test.go index 3aded05b93c..f7ca357736c 100644 --- a/scheduler/reconcile_test.go +++ b/scheduler/reconcile_test.go @@ -2537,6 +2537,52 @@ func TestReconciler_CreateDeployment_RollingUpgrade_Inplace(t *testing.T) { }) } +// Tests the reconciler creates a deployment when the job has a newer create index +func TestReconciler_CreateDeployment_NewerCreateIndex(t *testing.T) { + jobOld := mock.Job() + job := jobOld.Copy() + job.TaskGroups[0].Update = noCanaryUpdate + job.CreateIndex = 100 + + // Create 5 allocations from the old job + var allocs []*structs.Allocation + for i := 0; i < 5; i++ { + alloc := mock.Alloc() + alloc.Job = jobOld + alloc.JobID = jobOld.ID + alloc.NodeID = uuid.Generate() + alloc.Name = structs.AllocName(job.ID, job.TaskGroups[0].Name, uint(i)) + alloc.TaskGroup = job.TaskGroups[0].Name + allocs = append(allocs, alloc) + } + + reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, job.ID, job, nil, allocs, nil, "") + r := reconciler.Compute() + + d := structs.NewDeployment(job) + d.TaskGroups[job.TaskGroups[0].Name] = &structs.DeploymentState{ + DesiredTotal: 5, + } + + // Assert the correct results + assertResults(t, r, &resultExpectation{ + createDeployment: d, + deploymentUpdates: nil, + place: 5, + destructive: 0, + inplace: 0, + stop: 0, + desiredTGUpdates: map[string]*structs.DesiredUpdates{ + job.TaskGroups[0].Name: { + InPlaceUpdate: 0, + Ignore: 5, + Place: 5, + DestructiveUpdate: 0, + }, + }, + }) +} + // Tests the reconciler doesn't creates a deployment if there are no changes func TestReconciler_DontCreateDeployment_NoChanges(t *testing.T) { job := mock.Job() From 8e5909f073dc447421b1175379ccbe58ade3d7d0 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 5 Jun 2018 17:29:59 -0500 Subject: [PATCH 2/2] make test create index clearer --- scheduler/reconcile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler/reconcile_test.go b/scheduler/reconcile_test.go index f7ca357736c..5e039a7a9ff 100644 --- a/scheduler/reconcile_test.go +++ b/scheduler/reconcile_test.go @@ -2542,7 +2542,7 @@ func TestReconciler_CreateDeployment_NewerCreateIndex(t *testing.T) { jobOld := mock.Job() job := jobOld.Copy() job.TaskGroups[0].Update = noCanaryUpdate - job.CreateIndex = 100 + job.CreateIndex += 100 // Create 5 allocations from the old job var allocs []*structs.Allocation