server: Validate config num schedulers is between 0 and num CPUs.#25441
Merged
server: Validate config num schedulers is between 0 and num CPUs.#25441
Conversation
jrasell
added a commit
that referenced
this pull request
Mar 19, 2025
jrasell
added a commit
that referenced
this pull request
Mar 19, 2025
14a3225 to
2cb15b8
Compare
2cb15b8 to
985efed
Compare
jrasell
added a commit
that referenced
this pull request
Mar 19, 2025
tgross
previously approved these changes
Mar 19, 2025
The `server.num_scheduler` configuration value should be a value between 0 and the number of CPUs on the machine. The Nomad agent was not validating the configuration parameter which meant you could use a negative value or a value much larger than the available machine CPUs. This change enforces validation of the configuration value both on server startup and when the agent is reloaded. The Nomad API was only performing negative value validation when updating the scheduler number via this method. This change adds to the validation to ensure the number is not greater than the CPUs on the machine.
ce4c204 to
9a12d74
Compare
mismithhisler
approved these changes
Mar 19, 2025
|
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The
server.num_schedulerconfiguration value should be a value between 0 and the number of CPUs on the machine. The Nomad agent was not validating the configuration parameter which meant you could use a negative value or a value much larger than the available machine CPUs. This change enforces validation of the configuration value both on server startup and when the agent is reloaded.The Nomad API was only performing negative value validation when updating the scheduler number via this method. This change adds to the validation to ensure the number is not greater than the CPUs on the machine.
Out documentation currently correctly states the expected value bounds: https://developer.hashicorp.com/nomad/docs/configuration/server#num_schedulers
Testing & Reproduction steps
Using the configuration example below, try starting a Nomad dev agent with various values using this change and before. In tests with the agent started, you can alter the value and send a SIGHUP signal to the agent to test reload validation.
To test the API change you can start a Nomad agent in dev mode then attempt to write the following data via the curl command
curl --request PUT --data @payload.json http://localhost:4646/v1/agent/schedulers/config:{ "enabled_schedulers": [ "service", "batch", "system", "sysbatch", "_core" ], "num_schedulers": 1000 }I went back and forth on the idea of just updating the
SchedulerWorkerPoolArgs.IsValidfunction only to get the validation we want. It would work, but the server has to be started before this check is triggered. I therefore decided to have both the config validation and the backend validation with the idea to expand the configuration validation to cover more cases and eventually plug this into theconfig validatecommand.Contributor Checklist
changelog entry using the
make clcommand.ensure regressions will be caught.
and job configuration, please update the Nomad website documentation to reflect this. Refer to
the website README for docs guidelines. Please also consider whether the
change requires notes within the upgrade guide.
Reviewer Checklist
backporting document.
in the majority of situations. The main exceptions are long-lived feature branches or merges where
history should be preserved.
within the public repository.