diff --git a/nomad/structs/funcs.go b/nomad/structs/funcs.go index 926bb16d2bb7..59debb7741a7 100644 --- a/nomad/structs/funcs.go +++ b/nomad/structs/funcs.go @@ -104,7 +104,7 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi // For each alloc, add the resources for _, alloc := range allocs { // Do not consider the resource impact of terminal allocations - if alloc.TerminalStatus() { + if alloc.ClientTerminalStatus() { continue } diff --git a/nomad/structs/funcs_test.go b/nomad/structs/funcs_test.go index 988e5527b239..985586b91994 100644 --- a/nomad/structs/funcs_test.go +++ b/nomad/structs/funcs_test.go @@ -256,6 +256,7 @@ func TestAllocsFit_TerminalAlloc_Old(t *testing.T) { // Should fit second allocation since it is terminal a2 := a1.Copy() a2.DesiredStatus = AllocDesiredStatusStop + a2.ClientStatus = AllocClientStatusComplete fit, _, used, err = AllocsFit(n, []*Allocation{a1, a2}, nil, false) require.NoError(err) require.True(fit) @@ -479,6 +480,7 @@ func TestAllocsFit_TerminalAlloc(t *testing.T) { // Should fit second allocation since it is terminal a2 := a1.Copy() a2.DesiredStatus = AllocDesiredStatusStop + a2.ClientStatus = AllocClientStatusComplete fit, dim, used, err := AllocsFit(n, []*Allocation{a1, a2}, nil, false) require.NoError(err) require.True(fit, dim) diff --git a/nomad/structs/network.go b/nomad/structs/network.go index 88a629abf8b4..ea4c037939e2 100644 --- a/nomad/structs/network.go +++ b/nomad/structs/network.go @@ -144,7 +144,7 @@ func (idx *NetworkIndex) SetNode(node *Node) (collide bool) { func (idx *NetworkIndex) AddAllocs(allocs []*Allocation) (collide bool) { for _, alloc := range allocs { // Do not consider the resource impact of terminal allocations - if alloc.TerminalStatus() { + if alloc.ClientTerminalStatus() { continue } diff --git a/scheduler/context.go b/scheduler/context.go index fa7b51648703..62761f527370 100644 --- a/scheduler/context.go +++ b/scheduler/context.go @@ -120,7 +120,7 @@ func (e *EvalContext) Reset() { func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, error) { // Get the existing allocations that are non-terminal ws := memdb.NewWatchSet() - proposed, err := e.state.AllocsByNodeTerminal(ws, nodeID, false) + proposed, err := e.state.AllocsByNode(ws, nodeID) if err != nil { return nil, err } @@ -141,6 +141,10 @@ func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, erro // update occurs, we do not double count and we override the old allocation. proposedIDs := make(map[string]*structs.Allocation, len(proposed)) for _, alloc := range proposed { + if alloc.ClientTerminalStatus() { + continue + } + proposedIDs[alloc.ID] = alloc } for _, alloc := range e.plan.NodeAllocation[nodeID] {