-
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
CLI Allow querying all namespaces for jobs and allocations #8183
Conversation
Expose AllNamespaces parameter so one can query all namespaces an operator has access to
Expose a `-all-namespaces` | `NOMAD_ALL_NAMESPACES` env var, so that the job subcommands can query jobs across all namespaces.
This implements the backend handling for querying across namespaces for allocation list endpoints.
@@ -32,6 +32,7 @@ func (s *HTTPServer) AllocsRequest(resp http.ResponseWriter, req *http.Request) | |||
if s.parse(resp, req, &args.Region, &args.QueryOptions) { | |||
return nil, nil | |||
} | |||
args.AllNamespaces, _ = strconv.ParseBool(req.URL.Query().Get("all_namespaces")) |
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.
Any reason not to add this into s.parse
?
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.
Ah, looking closer into parse it doesn't make as much sense, nvm
Superseded by #8192 |
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 allows an Enterprise operator to query for lists in jobs and allocations across all namespaces they have capabilities in.
UX
When
-all-namespaces
command line argument is set, or ifNOMAD_ALL_NAMESPACES
env var is set to truthy value (e.g.1
,true
),nomad job
andnomad alloc
commands will lookup relevant jobs/allocations in all namespaces they are authorized to.nomad job status -all-namespaces
will emit all the jobs across namespaces (with a namespace column added).nomad job status -all-namespaces foo
will return the job info forfoo
job regardless of which namespace is in; if there multiple foo jobs, the CLI will emit back an error message, indicating the possible values.Abandoned ideas
Defaulting to
-all-namespaces
I considered avoiding the additional argument and defaulting to all namespaces if no
--namespace
is specified. Such change would be a significant change in behavior that will surprise users.Using a sentinel namespace value
We could reserve a sentinel namespace value (e.g.
--namespace global
) to indicate querying all namespaces. However, operators currently can create any namespace, and introducing a special reserved value might collide with an existing namespace and result into confusion.Implementation Details
The implementation has three main components:
The RPC Handlers for
Job.List
andAlloc.List
acceptAllNamespaces
argument to indicate whether one should search all namespaces the request token has access to. This PR implementsAllocations.List
, asJob.List
was already updated in #8001 .Then the API and CLI components need to pass
AllNamespaces
appropriately. Due to the sheer number of endpoints this affects, I made the flags a global Client Meta/Config options.The CLI subcommands typically adhere to the following implementation pattern:
As such,
{Job|Alloc}.Get
RPC endpoints aren't modified, and as before must require the correct namespace being passed.Incidentally, we didn't need to add any indexes to the state store to accomodate this.
Alloc.List
already isn't indexed by namespaces, so checking multiple namespaces is roughly the same computationally intensive operation as the namespaced ones.Potential follow ups