nomad: plan apply handles update of existing allocation

This commit is contained in:
Armon Dadgar 2015-08-22 19:37:21 -07:00
parent 5705dc6398
commit c72e6cdb78
2 changed files with 38 additions and 2 deletions

View File

@ -172,9 +172,16 @@ func evaluateNodePlan(snap *state.StateSnapshot, plan *structs.Plan, nodeID stri
// Determine the proposed allocation by first removing allocations
// that are planned evictions and adding the new allocations.
proposed := existingAlloc
var remove []string
if evict := plan.NodeEvict[nodeID]; len(evict) > 0 {
proposed = structs.RemoveAllocs(existingAlloc, evict)
remove = append(remove, evict...)
}
if updated := plan.NodeAllocation[nodeID]; len(updated) > 0 {
for _, alloc := range updated {
remove = append(remove, alloc.ID)
}
}
proposed = structs.RemoveAllocs(existingAlloc, remove)
proposed = append(proposed, plan.NodeAllocation[nodeID]...)
// Check if these allocations fit

View File

@ -285,6 +285,35 @@ func TestPlanApply_EvalNodePlan_NodeFull(t *testing.T) {
[]*structs.Allocation{alloc})
snap, _ := state.Snapshot()
alloc2 := mock.Alloc()
alloc2.NodeID = node.ID
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_UpdateExisting(t *testing.T) {
alloc := mock.Alloc()
state := testStateStore(t)
node := mock.Node()
alloc.NodeID = node.ID
node.Resources = alloc.Resources
node.Reserved = nil
state.RegisterNode(1000, node)
state.UpdateAllocations(1001, nil,
[]*structs.Allocation{alloc})
snap, _ := state.Snapshot()
plan := &structs.Plan{
NodeAllocation: map[string][]*structs.Allocation{
node.ID: []*structs.Allocation{alloc},
@ -295,7 +324,7 @@ func TestPlanApply_EvalNodePlan_NodeFull(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
if fit {
if !fit {
t.Fatalf("bad")
}
}