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

CLI Allow querying all namespaces for jobs and allocations - Try 2 #8192

Merged
merged 5 commits into from
Jun 19, 2020

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented Jun 17, 2020

This is attempt 2 of #8183 .

This is almost the same approach, but reuses current namespace field but with specially handling * to mean all namespaces.

UX

When -namespace=* command line argument is set, or if NOMAD_NAMESPACES env var is set to *, nomad job and nomad alloc commands will lookup relevant jobs/allocations in all namespaces they are authorized to.

nomad job status -namespace=* will emit all the jobs across namespaces (with a namespace column added). nomad job status -namespace=* foo will return the job info for foo job regardless of which namespace is in; if there multiple foo jobs, the CLI will emit back an error message, indicating the possible values.

# namespace specific status
$ nomad job status
ID        Type   Priority  Status   Submit Date
example1  batch  50        running  2020-06-17T10:49:26-04:00

# list jobs across all namespaces
$ nomad job status -namespace=*
ID        Namespace  Type   Priority  Status   Submit Date
example1  default    batch  50        running  2020-06-17T10:49:26-04:00
example1  qa         batch  50        running  2020-06-17T10:49:37-04:00
qa-job    qa         batch  50        running  2020-06-17T10:50:28-04:00

# get job status for a job in a specific namespace
$ nomad job status -short ex
ID            = example1
Name          = example1
Submit Date   = 2020-06-17T10:49:26-04:00
Type          = batch
Priority      = 50
Datacenters   = dc1
Namespace     = default
Status        = running
Periodic      = false
Parameterized = false

# when checking multiple namespaces, report an error message if multiples are found
$ nomad job status -short -namespace=* ex
Prefix matched multiple jobs

ID        Namespace  Type   Priority  Status   Submit Date
example1  default    batch  50        running  2020-06-17T10:49:26-04:00
example1  qa         batch  50        running  2020-06-17T10:49:37-04:00

# but namespace can always be specified to disambiguate
$ nomad job status -short -namespace qa ex
ID            = example1
Name          = example1
Submit Date   = 2020-06-17T10:49:37-04:00
Type          = batch
Priority      = 50
Datacenters   = dc1
Namespace     = qa
Status        = running
Periodic      = false
Parameterized = false

# querying with a prefix if a uniue job is found works
$ nomad job status -short -namespace=* qa
ID            = qa-job
Name          = qa-job
Submit Date   = 2020-06-17T10:50:28-04:00
Type          = batch
Priority      = 50
Datacenters   = dc1
Namespace     = qa
Status        = running
Periodic      = false
Parameterized = false

Implementation

The implementation is very identical to other approach

Trade-offs?

The advantage of this approach is that it's simpler to explain, has fewer moving parts, and provides a simple generalizable approach for other fields.

The downside though is that operators may need to fine tune namespace parameter in invocation basis. If a user sets NOMAD_NAMESPACE=*, they may get odd errors if hitting endpoints that don't support this yet (e.g. evals). Though, we should try to extend them to eliminate this annoying inconsistency if they exist.

Mahmood Ali added 5 commits June 17, 2020 16:27
This reverts the introduction of AllNamespaces parameter that was merged
earlier but never got released.
This implements the backend handling for querying across namespaces for
allocation list endpoints.
@notnoop notnoop requested a review from schmichael June 17, 2020 20:57
@notnoop notnoop added this to the 0.12.0 milestone Jun 18, 2020
@notnoop notnoop self-assigned this Jun 18, 2020
Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we could add globbing pretty easily since:

  1. we already use https://github.com/ryanuber/go-glob
  2. we already loop over every namespace to build the set
  3. we already loop over all objects in every namespace

So it'd be a little more CPU work per-namespace, but not listed per-object, so it seems fine.

Not a blocker for this.

@github-actions
Copy link

github-actions bot commented Jan 2, 2023

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants