Skip to content

Commit

Permalink
Merge pull request #4764 from hashicorp/b-reconciler-markstop-filtert…
Browse files Browse the repository at this point in the history
…erminal

Allocs already in terminal state do not need to be updated in the reconciler
  • Loading branch information
Preetha authored Oct 9, 2018
2 parents 4568da6 + dfc76b3 commit 60a3f62
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions scheduler/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (a *allocReconciler) cancelDeployments() {
// handleStop marks all allocations to be stopped, handling the lost case
func (a *allocReconciler) handleStop(m allocMatrix) {
for group, as := range m {
as = filterByTerminal(as)
untainted, migrate, lost := as.filterByTainted(a.taintedNodes)
a.markStop(untainted, "", allocNotNeeded)
a.markStop(migrate, "", allocNotNeeded)
Expand Down
62 changes: 62 additions & 0 deletions scheduler/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,68 @@ func TestReconciler_JobStopped(t *testing.T) {
}
}

// Tests the reconciler doesn't update allocs in terminal state
// when job is stopped or nil
func TestReconciler_JobStopped_TerminalAllocs(t *testing.T) {
job := mock.Job()
job.Stop = true

cases := []struct {
name string
job *structs.Job
jobID, taskGroup string
}{
{
name: "stopped job",
job: job,
jobID: job.ID,
taskGroup: job.TaskGroups[0].Name,
},
{
name: "nil job",
job: nil,
jobID: "foo",
taskGroup: "bar",
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
// Create 10 terminal allocations
var allocs []*structs.Allocation
for i := 0; i < 10; i++ {
alloc := mock.Alloc()
alloc.Job = c.job
alloc.JobID = c.jobID
alloc.NodeID = uuid.Generate()
alloc.Name = structs.AllocName(c.jobID, c.taskGroup, uint(i))
alloc.TaskGroup = c.taskGroup
if i%2 == 0 {
alloc.DesiredStatus = structs.AllocDesiredStatusStop
} else {
alloc.ClientStatus = structs.AllocClientStatusFailed
}
allocs = append(allocs, alloc)
}

reconciler := NewAllocReconciler(testlog.HCLogger(t), allocUpdateFnIgnore, false, c.jobID, c.job, nil, allocs, nil, "")
r := reconciler.Compute()
require.Len(t, r.stop, 0)
// Assert the correct results
assertResults(t, r, &resultExpectation{
createDeployment: nil,
deploymentUpdates: nil,
place: 0,
inplace: 0,
stop: 0,
desiredTGUpdates: map[string]*structs.DesiredUpdates{
c.taskGroup: {},
},
})
})
}
}

// Tests the reconciler properly handles jobs with multiple task groups
func TestReconciler_MultiTG(t *testing.T) {
job := mock.Job()
Expand Down

0 comments on commit 60a3f62

Please sign in to comment.