-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Make number of scheduler workers reloadable #11593
Merged
Merged
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
1908187
Working POC
angrycub 0071e55
Unexport setupNewWorkers; improve comments
angrycub 763671a
Added some VSCode codetours
angrycub 339316a
Update shutdown to use context
angrycub 1a985b3
Apply suggestions from code review
angrycub 22f93b7
Implement GET for SchedulerWorker API + tests
angrycub 16f9dd4
Merge branch 'f-reload-num-schedulers' of github.com:hashicorp/nomad …
angrycub 48428e7
Wired API, refactors, more testing
angrycub 1258128
Merge branch 'main' into f-reload-num-schedulers
angrycub 1845577
Fix linter complaints
angrycub 9c4e5c4
Updating worker to cache EnabledScheduler list
angrycub 0d8b7ec
Refactor `unsafe...` func names to `...Locked`
angrycub f5bb227
Passing enabled schedulers list to worker
angrycub 292518b
Add note about scheduler death
angrycub 1337f04
Worker API refactor
angrycub bd345e0
Made handler methods public for OpenAPI, remove unused test bool
angrycub 31687cd
Implement SchedulerWorker status part 1
angrycub 3739987
Fix broken Pause logic; split WorkloadWaiting status
angrycub 7fe5949
Added scheduler info api
angrycub 60d53fa
Added worker info api to api package
angrycub 3d755aa
bugfixes
angrycub 4ee6b8c
Adding stringer to build deps
angrycub 71dab36
Changing route to /v1/agent/schedulers
angrycub 1dc9f96
Adding docs for scheduler worker api
angrycub 0417332
Adding API test for bad worker info
angrycub 420a158
Add changelog message
angrycub fd016de
typo in changelog 🤦
angrycub 167c6a3
Incorporate API code review feedback
angrycub f4f610b
Incorporate api-docs feedback
angrycub 689fa77
Updates to worker/leader code from code review
angrycub 982c397
Fix test response type
angrycub 7581957
Set both statuses in markStopped so they are atomic
angrycub 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1470,7 +1470,6 @@ func TestHTTP_XSS_Monitor(t *testing.T) { | |
type scheduleWorkerTest_workerRequestTest struct { | ||
name string // test case name | ||
requiresACL bool // prevents test cases that require ACLs from running in the non-ACL version | ||
serverConfig AgentSchedulerWorkerConfig | ||
request schedulerWorkerTest_testRequest | ||
whenACLNotEnabled schedulerWorkerTest_testExpect | ||
whenACLEnabled schedulerWorkerTest_testExpect | ||
|
@@ -1485,19 +1484,6 @@ type schedulerWorkerTest_testExpect struct { | |
expectedResponse interface{} | ||
} | ||
|
||
// schedulerWorkerTest_serverConfig creates a test function that can merge | ||
// in an existing Config. Passing nil as the parameter will not override any | ||
// thing. | ||
func schedulerWorkerTest_serverConfig(inConfig *Config) func(*Config) { | ||
if inConfig != nil { | ||
return func(c *Config) { | ||
inConfig.Merge(c) | ||
} | ||
} else { | ||
return func(c *Config) {} | ||
} | ||
} | ||
|
||
// These test cases are run for both the ACL and Non-ACL enabled servers. When | ||
// ACLS are not enabled, the request.aclTokens are ignored. | ||
func schedulerWorkerTest_testCases() []scheduleWorkerTest_workerRequestTest { | ||
|
@@ -1511,7 +1497,12 @@ func schedulerWorkerTest_testCases() []scheduleWorkerTest_workerRequestTest { | |
} | ||
success1 := schedulerWorkerTest_testExpect{ | ||
expectedResponseCode: http.StatusOK, | ||
expectedResponse: &AgentSchedulerWorkerConfig{EnabledSchedulers: []string{"_core", "system"}, NumSchedulers: 8}, | ||
expectedResponse: &agentSchedulerWorkerConfig{EnabledSchedulers: []string{"_core", "batch"}, NumSchedulers: 8}, | ||
} | ||
|
||
success2 := schedulerWorkerTest_testExpect{ | ||
expectedResponseCode: http.StatusOK, | ||
expectedResponse: &agentSchedulerWorkerConfig{EnabledSchedulers: []string{"_core", "batch"}, NumSchedulers: 9}, | ||
} | ||
|
||
return []scheduleWorkerTest_workerRequestTest{ | ||
|
@@ -1572,17 +1563,17 @@ func schedulerWorkerTest_testCases() []scheduleWorkerTest_workerRequestTest { | |
request: schedulerWorkerTest_testRequest{ | ||
verb: "POST", | ||
aclToken: "", | ||
requestBody: "", | ||
requestBody: `{"num_schedulers":9,"enabled_schedulers":["_core", "batch"]}`, | ||
}, | ||
whenACLNotEnabled: success1, | ||
whenACLNotEnabled: success2, | ||
whenACLEnabled: forbidden, | ||
}, | ||
{ | ||
name: "put with no token", | ||
request: schedulerWorkerTest_testRequest{ | ||
verb: "PUT", | ||
aclToken: "", | ||
requestBody: "", | ||
requestBody: `{"num_schedulers":8,"enabled_schedulers":["_core", "batch"]}`, | ||
}, | ||
whenACLNotEnabled: success1, | ||
whenACLEnabled: forbidden, | ||
|
@@ -1592,17 +1583,17 @@ func schedulerWorkerTest_testCases() []scheduleWorkerTest_workerRequestTest { | |
request: schedulerWorkerTest_testRequest{ | ||
verb: "POST", | ||
aclToken: "node_write", | ||
requestBody: "", | ||
requestBody: `{"num_schedulers":9,"enabled_schedulers":["_core", "batch"]}`, | ||
}, | ||
whenACLNotEnabled: success1, | ||
whenACLNotEnabled: success2, | ||
whenACLEnabled: forbidden, | ||
}, | ||
{ | ||
name: "put with invalid token", | ||
request: schedulerWorkerTest_testRequest{ | ||
verb: "PUT", | ||
aclToken: "node_write", | ||
requestBody: "", | ||
requestBody: `{"num_schedulers":8,"enabled_schedulers":["_core", "batch"]}`, | ||
}, | ||
whenACLNotEnabled: success1, | ||
whenACLEnabled: forbidden, | ||
|
@@ -1612,17 +1603,17 @@ func schedulerWorkerTest_testCases() []scheduleWorkerTest_workerRequestTest { | |
request: schedulerWorkerTest_testRequest{ | ||
verb: "POST", | ||
aclToken: "agent_write", | ||
requestBody: "", | ||
requestBody: `{"num_schedulers":9,"enabled_schedulers":["_core", "batch"]}`, | ||
}, | ||
whenACLNotEnabled: success1, | ||
whenACLEnabled: success1, | ||
whenACLNotEnabled: success2, | ||
whenACLEnabled: success2, | ||
}, | ||
{ | ||
name: "put with valid token", | ||
request: schedulerWorkerTest_testRequest{ | ||
verb: "PUT", | ||
aclToken: "agent_write", | ||
requestBody: "", | ||
requestBody: `{"num_schedulers":8,"enabled_schedulers":["_core", "batch"]}`, | ||
}, | ||
whenACLNotEnabled: success1, | ||
whenACLEnabled: success1, | ||
|
@@ -1634,17 +1625,17 @@ func TestHTTP_AgentSchedulerWorkerRequest_NoACL(t *testing.T) { | |
configFn := func(c *Config) { | ||
var numSchedulers = 8 | ||
c.Server.NumSchedulers = &numSchedulers | ||
c.Server.EnabledSchedulers = []string{"_core", "system"} | ||
c.Server.EnabledSchedulers = []string{"_core", "batch"} | ||
c.Client.Enabled = false | ||
} | ||
testFn := func(s *TestAgent) { | ||
for _, tc := range schedulerWorkerTest_testCases() { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
||
req, err := http.NewRequest(tc.request.verb, "/v1/agent/workers", nil) | ||
req, err := http.NewRequest(tc.request.verb, "/v1/agent/workers", bytes.NewReader([]byte(tc.request.requestBody))) | ||
angrycub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.Nil(t, err) | ||
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. Nitpick: while |
||
respW := httptest.NewRecorder() | ||
workersI, err := s.Server.AgentSchedulerWorkerRequest(respW, req) | ||
workersI, err := s.Server.AgentSchedulerWorkerConfigRequest(respW, req) | ||
|
||
switch tc.whenACLNotEnabled.expectedResponseCode { | ||
case http.StatusBadRequest, http.StatusForbidden, http.StatusMethodNotAllowed: | ||
|
@@ -1665,7 +1656,7 @@ func TestHTTP_AgentSchedulerWorkerRequest_ACL(t *testing.T) { | |
configFn := func(c *Config) { | ||
var numSchedulers = 8 | ||
c.Server.NumSchedulers = &numSchedulers | ||
c.Server.EnabledSchedulers = []string{"_core", "system"} | ||
c.Server.EnabledSchedulers = []string{"_core", "batch"} | ||
c.Client.Enabled = false | ||
} | ||
|
||
|
@@ -1681,14 +1672,13 @@ func TestHTTP_AgentSchedulerWorkerRequest_ACL(t *testing.T) { | |
for _, tc := range schedulerWorkerTest_testCases() { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
||
req, err := http.NewRequest(tc.request.verb, "/v1/agent/workers", nil) | ||
req, err := http.NewRequest(tc.request.verb, "/v1/agent/workers", bytes.NewReader([]byte(tc.request.requestBody))) | ||
if tc.request.aclToken != "" { | ||
setToken(req, tokens[tc.request.aclToken]) | ||
} | ||
require.Nil(t, err) | ||
|
||
respW := httptest.NewRecorder() | ||
workersI, err := s.Server.AgentSchedulerWorkerRequest(respW, req) | ||
workersI, err := s.Server.AgentSchedulerWorkerConfigRequest(respW, req) | ||
|
||
switch tc.whenACLEnabled.expectedResponseCode { | ||
case http.StatusOK: | ||
|
@@ -1715,19 +1705,20 @@ func schedulerWorkerTest_parseSuccess(t *testing.T, isACLEnabled bool, tc schedu | |
} | ||
|
||
// test into the response when we expect an okay | ||
tcConfig, ok := testExpect.expectedResponse.(*AgentSchedulerWorkerConfig) | ||
tcConfig, ok := testExpect.expectedResponse.(*agentSchedulerWorkerConfig) | ||
require.True(t, ok, "expected response malformed - this is an issue with a test case.") | ||
|
||
workersConfig, ok := workersI.(*AgentSchedulerWorkerConfig) | ||
require.True(t, ok, "response can not cast to an AgentSchedulerWorkerConfig") | ||
workersConfig, ok := workersI.(*agentSchedulerWorkerConfig) | ||
require.True(t, ok, "response can not cast to an agentSchedulerWorkerConfig") | ||
require.NotNil(t, workersConfig) | ||
|
||
require.Equal(t, tcConfig.NumSchedulers, workersConfig.NumSchedulers) | ||
require.ElementsMatch(t, tcConfig.EnabledSchedulers, workersConfig.EnabledSchedulers) | ||
} | ||
|
||
// schedulerWorkerTest_parseError parses the error response given | ||
// from the | ||
// from the API call to make sure that it's a coded error and is the | ||
// expected value from the test case | ||
func schedulerWorkerTest_parseError(t *testing.T, isACLEnabled bool, tc scheduleWorkerTest_workerRequestTest, workersI interface{}, err error) { | ||
require.Error(t, err) | ||
require.Nil(t, workersI) | ||
|
@@ -1737,7 +1728,7 @@ func schedulerWorkerTest_parseError(t *testing.T, isACLEnabled bool, tc schedule | |
testExpect := tc.whenACLNotEnabled | ||
|
||
if isACLEnabled { | ||
testExpect = tc.whenACLNotEnabled | ||
testExpect = tc.whenACLEnabled | ||
} | ||
|
||
require.Equal(t, testExpect.expectedResponseCode, codedError.Code()) | ||
|
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.
I think we need
WriteOptions
here (andQueryOptions
forGetSchedulerConfig
above) to support ACLs and any HTTP params we might want in the future. And we always seem to want it eventually so that way we don't have to make aSetSchedulerWorkerConfigWithOptions
later on.We can probably get away without having a
QueryMeta
returned here because everything inQueryMeta
is used for comes out of raft? None of the other agent APIs in this file have it.