mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
Unblock evals once eligible
This commit is contained in:
committed by
Michael Schurter
parent
d6399cb733
commit
451b77d5d7
15
nomad/fsm.go
15
nomad/fsm.go
@@ -344,10 +344,25 @@ func (n *nomadFSM) applyNodeEligibilityUpdate(buf []byte, index uint64) interfac
|
||||
panic(fmt.Errorf("failed to decode request: %v", err))
|
||||
}
|
||||
|
||||
// Lookup the existing node
|
||||
node, err := n.state.NodeByID(nil, req.NodeID)
|
||||
if err != nil {
|
||||
n.logger.Printf("[ERR] nomad.fsm: UpdateNodeEligibility failed to lookup node %q: %v", req.NodeID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := n.state.UpdateNodeEligibility(index, req.NodeID, req.Eligibility); err != nil {
|
||||
n.logger.Printf("[ERR] nomad.fsm: UpdateNodeEligibility failed: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Unblock evals for the nodes computed node class if it is in a ready
|
||||
// state.
|
||||
if node != nil && node.SchedulingEligibility == structs.NodeSchedulingIneligible &&
|
||||
req.Eligibility == structs.NodeSchedulingEligible {
|
||||
n.blockedEvals.Unblock(node.ComputedClass, index)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -377,6 +377,60 @@ func TestFSM_UpdateNodeEligibility(t *testing.T) {
|
||||
require.Contains(err.Error(), "draining")
|
||||
}
|
||||
|
||||
func TestFSM_UpdateNodeEligibility_Unblock(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
fsm := testFSM(t)
|
||||
|
||||
node := mock.Node()
|
||||
req := structs.NodeRegisterRequest{
|
||||
Node: node,
|
||||
}
|
||||
buf, err := structs.Encode(structs.NodeRegisterRequestType, req)
|
||||
require.Nil(err)
|
||||
|
||||
resp := fsm.Apply(makeLog(buf))
|
||||
require.Nil(resp)
|
||||
|
||||
// Set the eligibility
|
||||
req2 := structs.NodeUpdateEligibilityRequest{
|
||||
NodeID: node.ID,
|
||||
Eligibility: structs.NodeSchedulingIneligible,
|
||||
}
|
||||
buf, err = structs.Encode(structs.NodeUpdateEligibilityRequestType, req2)
|
||||
require.Nil(err)
|
||||
|
||||
resp = fsm.Apply(makeLog(buf))
|
||||
require.Nil(resp)
|
||||
|
||||
// Mark an eval as blocked.
|
||||
eval := mock.Eval()
|
||||
eval.ClassEligibility = map[string]bool{node.ComputedClass: true}
|
||||
fsm.blockedEvals.Block(eval)
|
||||
|
||||
// Set eligible
|
||||
req4 := structs.NodeUpdateEligibilityRequest{
|
||||
NodeID: node.ID,
|
||||
Eligibility: structs.NodeSchedulingEligible,
|
||||
}
|
||||
buf, err = structs.Encode(structs.NodeUpdateEligibilityRequestType, req4)
|
||||
require.Nil(err)
|
||||
|
||||
resp = fsm.Apply(makeLog(buf))
|
||||
require.Nil(resp)
|
||||
|
||||
// Verify the eval was unblocked.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
bStats := fsm.blockedEvals.Stats()
|
||||
if bStats.TotalBlocked != 0 {
|
||||
return false, fmt.Errorf("bad: %#v", bStats)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFSM_RegisterJob(t *testing.T) {
|
||||
t.Parallel()
|
||||
fsm := testFSM(t)
|
||||
|
||||
Reference in New Issue
Block a user