diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index e51280ca9..f2a22092d 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -211,6 +211,9 @@ func (s *GenericScheduler) computeJobAllocs() error { s.eval.JobID, err) } + // Filter out the allocations in a terminal state + allocs = structs.FilterTerminalAllocs(allocs) + // Determine the tainted nodes containing job allocs tainted, err := taintedNodes(s.state, allocs) if err != nil { diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index 61a1534d2..b6cef7837 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -139,6 +139,19 @@ func TestServiceSched_JobModify(t *testing.T) { } noErr(t, h.State.UpsertAllocs(h.NextIndex(), allocs)) + // Add a few terminal status allocations, these should be ignored + var terminal []*structs.Allocation + for i := 0; i < 5; i++ { + alloc := mock.Alloc() + alloc.Job = job + alloc.JobID = job.ID + alloc.NodeID = nodes[i].ID + alloc.Name = fmt.Sprintf("my-job.web[%d]", i) + alloc.DesiredStatus = structs.AllocDesiredStatusFailed + terminal = append(terminal, alloc) + } + noErr(t, h.State.UpsertAllocs(h.NextIndex(), terminal)) + // Update the job job2 := mock.Job() job2.ID = job.ID