-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Node Drain Metadata #10250
Merged
Merged
Node Drain Metadata #10250
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0406d4b
wip: rebase
cgbaker 38fbdd3
node drain metadata wip
cgbaker ed88a0d
wip: more work on node drain metadata, needs testing
cgbaker 00bc7a4
updated tests
cgbaker 8bccba0
added node drain metadata to drain CLI command, tweaked SDK interface
cgbaker 9132b3d
better handling for drain no-ops
cgbaker a7cbda4
clean up metadata handling for node drain CLI
cgbaker c9bf393
clarified some code around node drain in the state store
cgbaker 5d91dda
changelog for #10250
cgbaker cb1c8da
corrected CLI documentation for `-meta`
cgbaker 25fb1cc
node drain metadata documentation (API and CLI)
cgbaker b83eae2
Update nomad/state/state_store_test.go
cgbaker c5e8c7f
Update nomad/state/state_store_test.go
cgbaker bb85f07
Update nomad/state/state_store_test.go
cgbaker a222ac6
Update command/node_drain.go
cgbaker 6584699
Update nomad/state/state_store.go
cgbaker c504359
set node drain status as a custom type
lgfa29 cd4dddf
fix test for node drain metadata
lgfa29 180f8a5
more test fixes
lgfa29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,13 +43,13 @@ func TestHTTP_NodesList(t *testing.T) { | |
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
if respW.Header().Get("X-Nomad-Index") == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of these are because |
||
t.Fatalf("missing index") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-KnownLeader") != "true" { | ||
if respW.Header().Get("X-Nomad-KnownLeader") != "true" { | ||
t.Fatalf("missing known leader") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-LastContact") == "" { | ||
if respW.Header().Get("X-Nomad-LastContact") == "" { | ||
t.Fatalf("missing last contact") | ||
} | ||
|
||
|
@@ -100,13 +100,13 @@ func TestHTTP_NodesPrefixList(t *testing.T) { | |
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
if respW.Header().Get("X-Nomad-Index") == "" { | ||
t.Fatalf("missing index") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-KnownLeader") != "true" { | ||
if respW.Header().Get("X-Nomad-KnownLeader") != "true" { | ||
t.Fatalf("missing known leader") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-LastContact") == "" { | ||
if respW.Header().Get("X-Nomad-LastContact") == "" { | ||
t.Fatalf("missing last contact") | ||
} | ||
|
||
|
@@ -158,7 +158,7 @@ func TestHTTP_NodeForceEval(t *testing.T) { | |
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
if respW.Header().Get("X-Nomad-Index") == "" { | ||
t.Fatalf("missing index") | ||
} | ||
|
||
|
@@ -218,13 +218,13 @@ func TestHTTP_NodeAllocations(t *testing.T) { | |
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
if respW.Header().Get("X-Nomad-Index") == "" { | ||
t.Fatalf("missing index") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-KnownLeader") != "true" { | ||
if respW.Header().Get("X-Nomad-KnownLeader") != "true" { | ||
t.Fatalf("missing known leader") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-LastContact") == "" { | ||
if respW.Header().Get("X-Nomad-LastContact") == "" { | ||
t.Fatalf("missing last contact") | ||
} | ||
|
||
|
@@ -257,8 +257,13 @@ func TestHTTP_NodeDrain(t *testing.T) { | |
DrainSpec: &api.DrainSpec{ | ||
Deadline: 10 * time.Second, | ||
}, | ||
Meta: map[string]string{ | ||
"reason": "drain", | ||
}, | ||
} | ||
|
||
beforeDrain := time.Unix(time.Now().Unix(), 0) | ||
|
||
// Make the HTTP request | ||
buf := encodeReq(drainReq) | ||
req, err := http.NewRequest("POST", "/v1/node/"+node.ID+"/drain", buf) | ||
|
@@ -270,13 +275,13 @@ func TestHTTP_NodeDrain(t *testing.T) { | |
require.Nil(err) | ||
|
||
// Check for the index | ||
require.NotZero(respW.HeaderMap.Get("X-Nomad-Index")) | ||
require.NotEmpty(respW.Header().Get("X-Nomad-Index")) | ||
|
||
// Check the response | ||
dresp, ok := obj.(structs.NodeDrainUpdateResponse) | ||
require.True(ok) | ||
|
||
t.Logf("response index=%v node_update_index=0x%x", respW.HeaderMap.Get("X-Nomad-Index"), | ||
t.Logf("response index=%v node_update_index=0x%x", respW.Header().Get("X-Nomad-Index"), | ||
dresp.NodeModifyIndex) | ||
|
||
// Check that the node has been updated | ||
|
@@ -292,8 +297,16 @@ func TestHTTP_NodeDrain(t *testing.T) { | |
require.Equal(structs.NodeSchedulingIneligible, out.SchedulingEligibility) | ||
} | ||
|
||
require.NotNil(out.LastDrain) | ||
require.Equal(map[string]string{ | ||
"reason": "drain", | ||
}, out.LastDrain.Meta) | ||
|
||
// Make the HTTP request to unset drain | ||
drainReq.DrainSpec = nil | ||
drainReq.Meta = map[string]string{ | ||
"cancel_reason": "changed my mind", | ||
} | ||
buf = encodeReq(drainReq) | ||
req, err = http.NewRequest("POST", "/v1/node/"+node.ID+"/drain", buf) | ||
require.Nil(err) | ||
|
@@ -306,6 +319,19 @@ func TestHTTP_NodeDrain(t *testing.T) { | |
out, err = state.NodeByID(nil, node.ID) | ||
require.Nil(err) | ||
require.Nil(out.DrainStrategy) | ||
require.NotNil(out.LastDrain) | ||
require.False(out.LastDrain.StartedAt.Before(beforeDrain)) | ||
require.False(out.LastDrain.UpdatedAt.Before(out.LastDrain.StartedAt)) | ||
require.Contains([]structs.DrainStatus{structs.DrainStatusCanceled, structs.DrainStatusComplete}, out.LastDrain.Status) | ||
if out.LastDrain.Status == structs.DrainStatusComplete { | ||
require.Equal(map[string]string{ | ||
"reason": "drain", | ||
}, out.LastDrain.Meta) | ||
} else if out.LastDrain.Status == structs.DrainStatusCanceled { | ||
require.Equal(map[string]string{ | ||
"cancel_reason": "changed my mind", | ||
}, out.LastDrain.Meta) | ||
} | ||
}) | ||
} | ||
|
||
|
@@ -337,7 +363,7 @@ func TestHTTP_NodeEligible(t *testing.T) { | |
require.Nil(err) | ||
|
||
// Check for the index | ||
require.NotZero(respW.HeaderMap.Get("X-Nomad-Index")) | ||
require.NotZero(respW.Header().Get("X-Nomad-Index")) | ||
|
||
// Check the response | ||
_, ok := obj.(structs.NodeEligibilityUpdateResponse) | ||
|
@@ -403,7 +429,7 @@ func TestHTTP_NodePurge(t *testing.T) { | |
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
if respW.Header().Get("X-Nomad-Index") == "" { | ||
t.Fatalf("missing index") | ||
} | ||
|
||
|
@@ -456,13 +482,13 @@ func TestHTTP_NodeQuery(t *testing.T) { | |
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
if respW.Header().Get("X-Nomad-Index") == "" { | ||
t.Fatalf("missing index") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-KnownLeader") != "true" { | ||
if respW.Header().Get("X-Nomad-KnownLeader") != "true" { | ||
t.Fatalf("missing known leader") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-LastContact") == "" { | ||
if respW.Header().Get("X-Nomad-LastContact") == "" { | ||
t.Fatalf("missing last contact") | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed a new method, followed the
Jobs().RegisterOpts()
pattern so we'll never need to do this again 🤞