Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Smart Node Drain #4005

Closed
wants to merge 221 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
1a7d557
wip - struct updates
schmichael Jan 24, 2018
af6ad54
wip - deadline checking
schmichael Jan 24, 2018
910598a
wip - node drainer
schmichael Jan 25, 2018
8525673
wip - refine deadline timer
schmichael Jan 26, 2018
a0094b6
wip - adding migration strategy
schmichael Jan 26, 2018
fe27fa2
wip - adding migrate to jobspec
schmichael Jan 30, 2018
086ea32
wip - drainer
schmichael Feb 2, 2018
255df6c
wip - add migrate support to allow health watcher
schmichael Feb 2, 2018
34af62f
wip - refactor node drainer state initialization
schmichael Feb 3, 2018
a539782
wip - implement node watcher
schmichael Feb 7, 2018
d627246
wip - mainloop impl up to alloc stopping
schmichael Feb 9, 2018
ecf773f
wip - almost finish drainer mainloop
schmichael Feb 10, 2018
96f3465
wip - finish initial pass at node drainer **
schmichael Feb 14, 2018
ef0165a
wip - lots more comments from review with alex
schmichael Feb 15, 2018
3d65c26
wip - add more comments
schmichael Feb 15, 2018
e6faa75
wip - fix dumb compile errors
schmichael Feb 15, 2018
dec1b73
wip - one more compiler error
schmichael Feb 15, 2018
9fa07bf
wip - a test that at least runs!
schmichael Feb 15, 2018
840d993
wip - fix nextDeadline initialization
schmichael Feb 16, 2018
cdea7bf
wip - fix node watcher initialization
schmichael Feb 16, 2018
f1feb8d
wip - ignore canceled errors
schmichael Feb 16, 2018
538a7c8
wip - always trigger an initial run if there's a node draining
schmichael Feb 16, 2018
7719dc3
wip - logs logs logs logs logs
schmichael Feb 16, 2018
8565821
wip - test: watch for alloc replacements
schmichael Feb 16, 2018
694adda
wip - converting test to use test clients
schmichael Feb 16, 2018
e3891f2
wip - testlog env var support
schmichael Feb 16, 2018
3fd2422
wip - stop triggering drains on every node update
schmichael Feb 17, 2018
373762d
wip - start using rpcs in drain test
schmichael Feb 17, 2018
e1693e6
wip - fix panic in alloc watcher log line
schmichael Feb 17, 2018
b85ad98
wip - stop injecting Node because that breaks everything
schmichael Feb 17, 2018
0e3c445
improve mock driver Kill() logging
schmichael Feb 20, 2018
7b3d15f
wip - drainer: trace log every alloc drain
schmichael Feb 20, 2018
ef3b326
server: default to scheduling eligible in Node.Register
schmichael Feb 20, 2018
8fd8a87
server: consider scheduling eligibility in scheduling
schmichael Feb 20, 2018
e6934e5
wip - hack default drain strategy into server
schmichael Feb 20, 2018
cc561a4
wip - trigger drain properly in drain test
schmichael Feb 20, 2018
7ffa70c
wip - log prev alloc in test
schmichael Feb 21, 2018
8c46783
Allocation struct
dadgar Feb 21, 2018
9b9a9a9
RPC, FSM, State Store for marking DesiredTransistion
dadgar Feb 21, 2018
3023429
Fix tests
dadgar Feb 22, 2018
ad4a415
fix build tag
dadgar Feb 22, 2018
01dc0a4
wip - switch to job based watching
schmichael Feb 22, 2018
a437737
Test is ugly but it's passing \o/
schmichael Feb 22, 2018
d483f0b
transistion -> transition
schmichael Feb 23, 2018
5a00fda
wip - switch to new raft DesiredTransition message
schmichael Feb 23, 2018
ef8753c
wip - drain system jobs as well
schmichael Feb 23, 2018
9467e38
filterByTainted node should always migrate non-terminal migrating allocs
schmichael Feb 24, 2018
a98ed65
server: unsure we want to enforce having an eval right now
schmichael Feb 26, 2018
d446414
improve drain fsm/statestore tests
schmichael Feb 26, 2018
dfe7dab
Node.Drain takes strategy
dadgar Feb 23, 2018
8569c4b
Drain cli, api, http
dadgar Feb 23, 2018
51cff3e
Fix tests
dadgar Feb 26, 2018
b2a0be6
Remove update time
dadgar Feb 26, 2018
8a90a47
Upgrade path
dadgar Feb 27, 2018
9947bfd
flag comment
dadgar Feb 27, 2018
5e415b3
Merge pull request #3899 from hashicorp/f-drain-api
dadgar Feb 27, 2018
cdecd22
RPC/FSM/State Store for Eligibility
dadgar Feb 27, 2018
185e66b
HTTP and API
dadgar Feb 27, 2018
e05fb9b
node eligibility command
dadgar Feb 27, 2018
f40ffa1
Add eligibility to node view
dadgar Feb 27, 2018
e17bd34
Unblock evals once eligible
dadgar Feb 27, 2018
e9328c7
Fix retaining the drain
dadgar Feb 27, 2018
c2dc67f
Small refactor and cleanups
dadgar Feb 27, 2018
ffa6f4c
code review
dadgar Feb 27, 2018
8e9bf6b
Merge pull request #3919 from hashicorp/f-eligibility
dadgar Feb 27, 2018
5ffd310
refactor drainer into a subpkg
schmichael Feb 27, 2018
35dc5d4
drainer: drainer should shutdown with server
schmichael Feb 27, 2018
7f2d8fa
Remove unused context
schmichael Feb 27, 2018
6e5b7fc
Restart every time SetEnabled(true) is called
schmichael Feb 27, 2018
fc13aa7
drainer: factor job & node watchers out of drainer.go
schmichael Feb 27, 2018
984acf9
drainer: convert fsm errors to go errors
schmichael Feb 27, 2018
bda7ec7
Improve DeadlineTime helper
dadgar Mar 1, 2018
aaf392a
Merge pull request #3922 from hashicorp/f-deadline
dadgar Mar 1, 2018
95b9183
client: don't monitor health of non-service jobs
schmichael Feb 27, 2018
4ed2a5a
wip - fix system job draining; won't work without deadline fixes
schmichael Feb 28, 2018
37f5869
drainer: factor out newStopAllocs and applyMigrations
schmichael Mar 1, 2018
f5d57f8
small cleanups
schmichael Mar 1, 2018
80ba859
refactor main drainloop into 2 more methods
schmichael Mar 1, 2018
d822367
Correct defaulting
dadgar Mar 1, 2018
1a96c25
Merge pull request #3925 from hashicorp/b-defaulting
dadgar Mar 1, 2018
2318e1e
Fix file names
dadgar Mar 1, 2018
0df7acc
System test runs on mac
dadgar Mar 1, 2018
2938045
Initial design
dadgar Mar 2, 2018
f3ac2b4
drain heap
dadgar Mar 2, 2018
44f1cc5
node watcher
dadgar Mar 3, 2018
90da01e
Node's being untracked or having updated deadlines, updates the deadl…
dadgar Mar 3, 2018
ea4df19
job watcher
dadgar Mar 6, 2018
1e7186f
Drainer
dadgar Mar 6, 2018
eebca69
integration test and basic fixes
dadgar Mar 7, 2018
83d3555
handle empty node case
dadgar Mar 7, 2018
5abffa0
Comments
dadgar Mar 7, 2018
3e83591
spelling fixes
dadgar Mar 8, 2018
ef6a003
code review
dadgar Mar 8, 2018
0db7e8d
Merge pull request #3951 from hashicorp/f-drainer
dadgar Mar 8, 2018
309bcf8
Toggle Drain allows resetting eligibility
dadgar Mar 8, 2018
5efde3e
Merge pull request #3955 from hashicorp/f-manual-undrain
dadgar Mar 8, 2018
88c9d70
Switch to drainerv2 impl
schmichael Mar 8, 2018
8f4ce6e
Batch drain update
dadgar Mar 9, 2018
ffde29d
sharding
dadgar Mar 10, 2018
0e86233
Fix deadline handling
dadgar Mar 12, 2018
51bd58a
Merge pull request #3967 from hashicorp/b-deadline
dadgar Mar 12, 2018
a77c452
Fix node eligibility test
schmichael Mar 6, 2018
8b7b42c
Add DesiredTransition.ShouldMigrate to api pkg
schmichael Mar 7, 2018
14d76fc
Monitor node drains until completion in CLI
schmichael Mar 6, 2018
8506049
fix comment
dadgar Mar 14, 2018
f545e6a
Merge pull request #3960 from hashicorp/f-sharding
dadgar Mar 14, 2018
5c4ffd4
Improve drain log messages
schmichael Mar 16, 2018
b2d682b
Merge pull request #3948 from hashicorp/f-drainv2-cli
schmichael Mar 16, 2018
6c5d442
Fix deadline heap triggering
schmichael Mar 9, 2018
3429b7d
Fix job watcher index handling
schmichael Mar 10, 2018
c1ee664
wip test for job watcher
schmichael Mar 10, 2018
5733c7c
Revert making drains async
schmichael Mar 13, 2018
d18d2d7
Test job watcher
schmichael Mar 13, 2018
adc979e
wip - struct updates
schmichael Jan 24, 2018
84ab471
wip - deadline checking
schmichael Jan 24, 2018
c67be08
wip - node drainer
schmichael Jan 25, 2018
85eb9a1
wip - refine deadline timer
schmichael Jan 26, 2018
4533b03
wip - adding migration strategy
schmichael Jan 26, 2018
07225eb
wip - adding migrate to jobspec
schmichael Jan 30, 2018
540a696
wip - drainer
schmichael Feb 2, 2018
b57fb51
wip - add migrate support to allow health watcher
schmichael Feb 2, 2018
e9c63b9
wip - refactor node drainer state initialization
schmichael Feb 3, 2018
590f25a
wip - implement node watcher
schmichael Feb 7, 2018
b4b71a4
wip - mainloop impl up to alloc stopping
schmichael Feb 9, 2018
a6cc4dc
wip - almost finish drainer mainloop
schmichael Feb 10, 2018
6057ed5
wip - finish initial pass at node drainer **
schmichael Feb 14, 2018
518aa5f
wip - lots more comments from review with alex
schmichael Feb 15, 2018
0662421
wip - add more comments
schmichael Feb 15, 2018
4a9c6cb
wip - fix dumb compile errors
schmichael Feb 15, 2018
d061d89
wip - one more compiler error
schmichael Feb 15, 2018
47f7d70
wip - a test that at least runs!
schmichael Feb 15, 2018
151f2dc
wip - fix nextDeadline initialization
schmichael Feb 16, 2018
e0643d4
wip - fix node watcher initialization
schmichael Feb 16, 2018
4533b67
wip - ignore canceled errors
schmichael Feb 16, 2018
152f456
wip - always trigger an initial run if there's a node draining
schmichael Feb 16, 2018
1663428
wip - logs logs logs logs logs
schmichael Feb 16, 2018
f493d52
wip - test: watch for alloc replacements
schmichael Feb 16, 2018
910e7c8
wip - converting test to use test clients
schmichael Feb 16, 2018
c97c2e4
wip - testlog env var support
schmichael Feb 16, 2018
8ff951c
wip - stop triggering drains on every node update
schmichael Feb 17, 2018
bd3bfa5
wip - start using rpcs in drain test
schmichael Feb 17, 2018
0ea4f9f
wip - fix panic in alloc watcher log line
schmichael Feb 17, 2018
db419ec
wip - stop injecting Node because that breaks everything
schmichael Feb 17, 2018
1d25f33
improve mock driver Kill() logging
schmichael Feb 20, 2018
3914180
wip - drainer: trace log every alloc drain
schmichael Feb 20, 2018
d8615e7
server: default to scheduling eligible in Node.Register
schmichael Feb 20, 2018
9a36570
server: consider scheduling eligibility in scheduling
schmichael Feb 20, 2018
9e0f0eb
wip - hack default drain strategy into server
schmichael Feb 20, 2018
ad13507
wip - trigger drain properly in drain test
schmichael Feb 20, 2018
6e7227b
wip - log prev alloc in test
schmichael Feb 21, 2018
965c57b
Allocation struct
dadgar Feb 21, 2018
632fbd7
RPC, FSM, State Store for marking DesiredTransistion
dadgar Feb 21, 2018
75bf315
Fix tests
dadgar Feb 22, 2018
1a0bfbc
fix build tag
dadgar Feb 22, 2018
95aa121
wip - switch to job based watching
schmichael Feb 22, 2018
ab9df29
Test is ugly but it's passing \o/
schmichael Feb 22, 2018
db048bd
wip - switch to new raft DesiredTransition message
schmichael Feb 23, 2018
fc217d7
wip - drain system jobs as well
schmichael Feb 23, 2018
cde47ff
filterByTainted node should always migrate non-terminal migrating allocs
schmichael Feb 24, 2018
7cea5ee
server: unsure we want to enforce having an eval right now
schmichael Feb 26, 2018
6b80cd3
improve drain fsm/statestore tests
schmichael Feb 26, 2018
240d50b
Node.Drain takes strategy
dadgar Feb 23, 2018
a1466cf
Drain cli, api, http
dadgar Feb 23, 2018
7e0317d
Fix tests
dadgar Feb 26, 2018
e675257
Remove update time
dadgar Feb 26, 2018
e18cea5
Upgrade path
dadgar Feb 27, 2018
c901b21
flag comment
dadgar Feb 27, 2018
b02fd1e
JobNs -> NamespacedID
schmichael Mar 19, 2018
f3a1752
Deregister garbage collected jobs
schmichael Mar 19, 2018
1739290
Remove debug prints
schmichael Mar 19, 2018
43d5246
RPC/FSM/State Store for Eligibility
dadgar Feb 27, 2018
1c0aaa7
HTTP and API
dadgar Feb 27, 2018
a73398d
node eligibility command
dadgar Feb 27, 2018
4915b76
Add eligibility to node view
dadgar Feb 27, 2018
45db5ca
Unblock evals once eligible
dadgar Feb 27, 2018
9db4f7d
Fix retaining the drain
dadgar Feb 27, 2018
ab3fc5b
Small refactor and cleanups
dadgar Feb 27, 2018
b807fdc
code review
dadgar Feb 27, 2018
3f2d7f1
refactor drainer into a subpkg
schmichael Feb 27, 2018
b93142c
drainer: drainer should shutdown with server
schmichael Feb 27, 2018
10a3d38
Remove unused context
schmichael Feb 27, 2018
d78da97
Restart every time SetEnabled(true) is called
schmichael Feb 27, 2018
1753afa
drainer: factor job & node watchers out of drainer.go
schmichael Feb 27, 2018
7da9b61
drainer: convert fsm errors to go errors
schmichael Feb 27, 2018
e3dff57
Improve DeadlineTime helper
dadgar Mar 1, 2018
d58a50b
client: don't monitor health of non-service jobs
schmichael Feb 27, 2018
4d54ac1
wip - fix system job draining; won't work without deadline fixes
schmichael Feb 28, 2018
6c84ecd
drainer: factor out newStopAllocs and applyMigrations
schmichael Mar 1, 2018
c61db41
small cleanups
schmichael Mar 1, 2018
3a7d297
refactor main drainloop into 2 more methods
schmichael Mar 1, 2018
cd80e91
Correct defaulting
dadgar Mar 1, 2018
1304311
Fix file names
dadgar Mar 1, 2018
7fde810
System test runs on mac
dadgar Mar 1, 2018
e376f0b
Initial design
dadgar Mar 2, 2018
4f88361
drain heap
dadgar Mar 2, 2018
65edbb8
node watcher
dadgar Mar 3, 2018
58e3b35
Node's being untracked or having updated deadlines, updates the deadl…
dadgar Mar 3, 2018
2ed8896
job watcher
dadgar Mar 6, 2018
3a82359
Drainer
dadgar Mar 6, 2018
ba19415
integration test and basic fixes
dadgar Mar 7, 2018
4e96ac4
handle empty node case
dadgar Mar 7, 2018
2536ba9
Comments
dadgar Mar 7, 2018
7fba651
spelling fixes
dadgar Mar 8, 2018
0e7b37d
code review
dadgar Mar 8, 2018
6321a27
Toggle Drain allows resetting eligibility
dadgar Mar 8, 2018
6eef768
Switch to drainerv2 impl
schmichael Mar 8, 2018
da06b87
Batch drain update
dadgar Mar 9, 2018
3085f58
sharding
dadgar Mar 10, 2018
8b1fb9f
Refactor assertOps into a helper func
schmichael Mar 19, 2018
b4e5979
Merge pull request #3961 from hashicorp/f-drainv2-testing
schmichael Mar 19, 2018
5ed3c7b
Fix deadline handling
dadgar Mar 12, 2018
c4158c0
Fix node eligibility test
schmichael Mar 6, 2018
91b73cc
Add DesiredTransition.ShouldMigrate to api pkg
schmichael Mar 7, 2018
1c5aa73
Monitor node drains until completion in CLI
schmichael Mar 6, 2018
e987350
fix comment
dadgar Mar 14, 2018
4639dc7
Improve drain log messages
schmichael Mar 16, 2018
46de654
Merge branch 'f-drainv2-node-drainer' of github.com:hashicorp/nomad i…
dadgar Mar 19, 2018
f902c88
merge cleanup
dadgar Mar 19, 2018
6b732eb
Merge branch 'master' into f-drain-rebased
dadgar Mar 19, 2018
0482280
fix race in drain integration tests
dadgar Mar 19, 2018
59f3df9
Merge branch 'master' into f-drain-rebased
dadgar Mar 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Allocation struct {
Metrics *AllocationMetric
DesiredStatus string
DesiredDescription string
DesiredTransition DesiredTransition
ClientStatus string
ClientDescription string
TaskStates map[string]*TaskState
Expand Down Expand Up @@ -205,3 +206,17 @@ type RescheduleEvent struct {
// PrevNodeID is the node ID of the previous allocation
PrevNodeID string
}

// DesiredTransition is used to mark an allocation as having a desired state
// transition. This information can be used by the scheduler to make the
// correct decision.
type DesiredTransition struct {
// Migrate is used to indicate that this allocation should be stopped and
// migrated to another node.
Migrate *bool
}

// ShouldMigrate returns whether the transition object dictates a migration.
func (d DesiredTransition) ShouldMigrate() bool {
return d.Migrate != nil && *d.Migrate
}
7 changes: 7 additions & 0 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,10 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
}

}

func TestAllocations_ShouldMigrate(t *testing.T) {
t.Parallel()
require.True(t, DesiredTransition{Migrate: helper.BoolToPtr(true)}.ShouldMigrate())
require.False(t, DesiredTransition{}.ShouldMigrate())
require.False(t, DesiredTransition{Migrate: helper.BoolToPtr(false)}.ShouldMigrate())
}
1 change: 1 addition & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ type Job struct {
ParameterizedJob *ParameterizedJobConfig
Payload []byte
Reschedule *ReschedulePolicy
Migrate *MigrateStrategy
Meta map[string]string
VaultToken *string `mapstructure:"vault_token"`
Status *string
Expand Down
140 changes: 106 additions & 34 deletions api/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package api
import (
"fmt"
"sort"
"strconv"
"time"

"github.com/hashicorp/nomad/nomad/structs"
)

// Nodes is used to query node-related API endpoints
Expand Down Expand Up @@ -41,10 +43,56 @@ func (n *Nodes) Info(nodeID string, q *QueryOptions) (*Node, *QueryMeta, error)
return &resp, qm, nil
}

// ToggleDrain is used to toggle drain mode on/off for a given node.
func (n *Nodes) ToggleDrain(nodeID string, drain bool, q *WriteOptions) (*WriteMeta, error) {
drainArg := strconv.FormatBool(drain)
wm, err := n.client.write("/v1/node/"+nodeID+"/drain?enable="+drainArg, nil, nil, q)
// NodeUpdateDrainRequest is used to update the drain specification for a node.
type NodeUpdateDrainRequest struct {
// NodeID is the node to update the drain specification for.
NodeID string

// DrainSpec is the drain specification to set for the node. A nil DrainSpec
// will disable draining.
DrainSpec *DrainSpec

// MarkEligible marks the node as eligible if removing the drain strategy.
MarkEligible bool
}

// UpdateDrain is used to update the drain strategy for a given node. If
// markEligible is true and the drain is being removed, the node will be marked
// as having its scheduling being elibile
func (n *Nodes) UpdateDrain(nodeID string, spec *DrainSpec, markEligible bool, q *WriteOptions) (*WriteMeta, error) {
req := &NodeUpdateDrainRequest{
NodeID: nodeID,
DrainSpec: spec,
MarkEligible: markEligible,
}

wm, err := n.client.write("/v1/node/"+nodeID+"/drain", req, nil, q)
if err != nil {
return nil, err
}
return wm, nil
}

// NodeUpdateEligibilityRequest is used to update the drain specification for a node.
type NodeUpdateEligibilityRequest struct {
// NodeID is the node to update the drain specification for.
NodeID string
Eligibility string
}

// ToggleEligibility is used to update the scheduling eligibility of the node
func (n *Nodes) ToggleEligibility(nodeID string, eligible bool, q *WriteOptions) (*WriteMeta, error) {
e := structs.NodeSchedulingEligible
if !eligible {
e = structs.NodeSchedulingIneligible
}

req := &NodeUpdateEligibilityRequest{
NodeID: nodeID,
Eligibility: e,
}

wm, err := n.client.write("/v1/node/"+nodeID+"/eligibility", req, nil, q)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -98,24 +146,47 @@ func (n *Nodes) GcAlloc(allocID string, q *QueryOptions) error {

// Node is used to deserialize a node entry.
type Node struct {
ID string
Datacenter string
Name string
HTTPAddr string
TLSEnabled bool
Attributes map[string]string
Resources *Resources
Reserved *Resources
Links map[string]string
Meta map[string]string
NodeClass string
Drain bool
Status string
StatusDescription string
StatusUpdatedAt int64
Events []*NodeEvent
CreateIndex uint64
ModifyIndex uint64
ID string
Datacenter string
Name string
HTTPAddr string
TLSEnabled bool
Attributes map[string]string
Resources *Resources
Reserved *Resources
Links map[string]string
Meta map[string]string
NodeClass string
Drain bool
DrainStrategy *DrainStrategy
SchedulingEligibility string
Status string
StatusDescription string
StatusUpdatedAt int64
Events []*NodeEvent
CreateIndex uint64
ModifyIndex uint64
}

// DrainStrategy describes a Node's drain behavior.
type DrainStrategy struct {
// DrainSpec is the user declared drain specification
DrainSpec

// ForceDeadline is the deadline time for the drain after which drains will
// be forced
ForceDeadline time.Time
}

// DrainSpec describes a Node's drain behavior.
type DrainSpec struct {
// Deadline is the duration after StartTime when the remaining
// allocations on a draining Node should be told to stop.
Deadline time.Duration

// IgnoreSystemJobs allows systems jobs to remain on the node even though it
// has been marked for draining.
IgnoreSystemJobs bool
}

const (
Expand Down Expand Up @@ -170,17 +241,18 @@ type HostDiskStats struct {
// NodeListStub is a subset of information returned during
// node list operations.
type NodeListStub struct {
Address string
ID string
Datacenter string
Name string
NodeClass string
Version string
Drain bool
Status string
StatusDescription string
CreateIndex uint64
ModifyIndex uint64
Address string
ID string
Datacenter string
Name string
NodeClass string
Version string
Drain bool
SchedulingEligibility string
Status string
StatusDescription string
CreateIndex uint64
ModifyIndex uint64
}

// NodeIndexSort reverse sorts nodes by CreateIndex
Expand Down
83 changes: 79 additions & 4 deletions api/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ func TestNodes_ToggleDrain(t *testing.T) {
}

// Toggle it on
wm, err := nodes.ToggleDrain(nodeID, true, nil)
spec := &DrainSpec{
Deadline: 10 * time.Second,
}
wm, err := nodes.UpdateDrain(nodeID, spec, false, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -185,12 +188,12 @@ func TestNodes_ToggleDrain(t *testing.T) {
if err != nil {
t.Fatalf("err: %s", err)
}
if !out.Drain {
t.Fatalf("drain mode should be on")
if out.SchedulingEligibility != structs.NodeSchedulingIneligible {
t.Fatalf("bad eligibility: %v vs %v", out.SchedulingEligibility, structs.NodeSchedulingIneligible)
}

// Toggle off again
wm, err = nodes.ToggleDrain(nodeID, false, nil)
wm, err = nodes.UpdateDrain(nodeID, nil, true, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -204,6 +207,78 @@ func TestNodes_ToggleDrain(t *testing.T) {
if out.Drain {
t.Fatalf("drain mode should be off")
}
if out.DrainStrategy != nil {
t.Fatalf("drain strategy should be unset")
}
if out.SchedulingEligibility != structs.NodeSchedulingEligible {
t.Fatalf("should be eligible")
}
}

func TestNodes_ToggleEligibility(t *testing.T) {
t.Parallel()
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
c.DevMode = true
})
defer s.Stop()
nodes := c.Nodes()

// Wait for node registration and get the ID
var nodeID string
testutil.WaitForResult(func() (bool, error) {
out, _, err := nodes.List(nil)
if err != nil {
return false, err
}
if n := len(out); n != 1 {
return false, fmt.Errorf("expected 1 node, got: %d", n)
}
nodeID = out[0].ID
return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
})

// Check for eligibility
out, _, err := nodes.Info(nodeID, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if out.SchedulingEligibility != structs.NodeSchedulingEligible {
t.Fatalf("node should be eligible")
}

// Toggle it off
wm, err := nodes.ToggleEligibility(nodeID, false, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
assertWriteMeta(t, wm)

// Check again
out, _, err = nodes.Info(nodeID, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if out.SchedulingEligibility != structs.NodeSchedulingIneligible {
t.Fatalf("bad eligibility: %v vs %v", out.SchedulingEligibility, structs.NodeSchedulingIneligible)
}

// Toggle on
wm, err = nodes.ToggleEligibility(nodeID, true, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
assertWriteMeta(t, wm)

// Check again
out, _, err = nodes.Info(nodeID, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if out.SchedulingEligibility != structs.NodeSchedulingEligible {
t.Fatalf("bad eligibility: %v vs %v", out.SchedulingEligibility, structs.NodeSchedulingEligible)
}
}

func TestNodes_Allocations(t *testing.T) {
Expand Down
Loading