nomad: adding evicted state for allocs
This commit is contained in:
parent
5b2dc385ec
commit
f04e2b81ba
|
@ -365,12 +365,12 @@ func TestFSM_UpdateAllocations(t *testing.T) {
|
|||
t.Fatalf("resp: %v", resp)
|
||||
}
|
||||
|
||||
// Verify we are NOT registered
|
||||
// Verify we are evicted
|
||||
out, err = fsm.State().GetAllocByID(alloc.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if out != nil {
|
||||
if out.Status != structs.AllocStatusEvict {
|
||||
t.Fatalf("alloc found!")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,6 +166,9 @@ func evaluateNodePlan(snap *state.StateSnapshot, plan *structs.Plan, nodeID stri
|
|||
return false, fmt.Errorf("failed to get existing allocations for '%s': %v", node, err)
|
||||
}
|
||||
|
||||
// Filter on alloc state
|
||||
existingAlloc = structs.FilterTerminalAllocs(existingAlloc)
|
||||
|
||||
// Determine the proposed allocation by first removing allocations
|
||||
// that are planned evictions and adding the new allocations.
|
||||
proposed := existingAlloc
|
||||
|
|
|
@ -100,8 +100,8 @@ func TestPlanApply_applyPlan(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if out != nil {
|
||||
t.Fatalf("should be missing alloc")
|
||||
if out.Status != structs.AllocStatusEvict {
|
||||
t.Fatalf("should be evicted alloc")
|
||||
}
|
||||
|
||||
// Lookup the allocation
|
||||
|
@ -331,6 +331,35 @@ func TestPlanApply_EvalNodePlan_NodeFull_Evict(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPlanApply_EvalNodePlan_NodeFull_AllocEvict(t *testing.T) {
|
||||
alloc := mock.Alloc()
|
||||
state := testStateStore(t)
|
||||
node := mock.Node()
|
||||
alloc.NodeID = node.ID
|
||||
alloc.Status = structs.AllocStatusEvict
|
||||
node.Resources = alloc.Resources
|
||||
node.Reserved = nil
|
||||
state.RegisterNode(1000, node)
|
||||
state.UpdateAllocations(1001, nil,
|
||||
[]*structs.Allocation{alloc})
|
||||
snap, _ := state.Snapshot()
|
||||
|
||||
alloc2 := mock.Alloc()
|
||||
plan := &structs.Plan{
|
||||
NodeAllocation: map[string][]*structs.Allocation{
|
||||
node.ID: []*structs.Allocation{alloc2},
|
||||
},
|
||||
}
|
||||
|
||||
fit, err := evaluateNodePlan(snap, plan, node.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if !fit {
|
||||
t.Fatalf("bad")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanApply_EvalNodePlan_NodeMaint_EvictOnly(t *testing.T) {
|
||||
alloc := mock.Alloc()
|
||||
state := testStateStore(t)
|
||||
|
|
|
@ -421,8 +421,13 @@ func (s *StateStore) UpdateAllocations(index uint64, evicts []string,
|
|||
if existing == nil {
|
||||
continue
|
||||
}
|
||||
if err := txn.Delete("allocs", existing); err != nil {
|
||||
return fmt.Errorf("alloc delete failed: %v", err)
|
||||
newAlloc := new(structs.Allocation)
|
||||
*newAlloc = *existing.(*structs.Allocation)
|
||||
newAlloc.Status = structs.AllocStatusEvict
|
||||
newAlloc.StatusDescription = ""
|
||||
|
||||
if err := txn.Insert("allocs", newAlloc); err != nil {
|
||||
return fmt.Errorf("alloc insert failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -694,7 +694,7 @@ func TestStateStore_EvictAlloc_GetAlloc(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if out != nil {
|
||||
if out.Status != structs.AllocStatusEvict {
|
||||
t.Fatalf("bad: %#v %#v", alloc, out)
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,9 @@ func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, erro
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Filter on alloc state
|
||||
existingAlloc = structs.FilterTerminalAllocs(existingAlloc)
|
||||
|
||||
// Determine the proposed allocation by first removing allocations
|
||||
// that are planned evictions and adding the new allocations.
|
||||
proposed := existingAlloc
|
||||
|
|
Loading…
Reference in New Issue