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

endpoint to expose all jobs across all namespaces #8001

Merged
merged 4 commits into from
Jun 1, 2020

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented May 18, 2020

Allow a /v1/jobs?all_namespaces=true parameter to list all jobs across all
namespaces. The returned list is to contain a Namespace field
indicating the job namespace.

If ACL is enabled, the request token needs to be a management token or
have namespace:list-jobs capability on all existing namespaces.

Allow a `/v1/jobs?all_namespaces=true` to list all jobs across all
namespaces.  The returned list is to contain a `Namespace` field
indicating the job namespace.

If ACL is enabled, the request token needs to be a management token or
have `namespace:list-jobs` capability on all existing namespaces.
@notnoop notnoop added this to the 0.12.0 milestone May 18, 2020
@notnoop notnoop requested a review from schmichael May 18, 2020 18:13
@notnoop notnoop self-assigned this May 18, 2020
Copy link
Contributor

@cgbaker cgbaker left a comment

Choose a reason for hiding this comment

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

a few questions about the decision to go all-or-nothing based on the ACL token and the ListStub.


for _, ns := range nses {
if !aclObj.AllowNsOp(ns, acl.NamespaceCapabilityListJobs) {
return structs.ErrPermissionDenied
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is already linear-time/memory on the number of namespaces + the number of jobs, why not use the token as a filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow the intent - is the suggestion to keep the filtering logic but call aclObj.AllowNsOps(...) on every job rather than every namespaces? That's seems unnecessary wasteful. I'd assume there are orders of magnitudes more jobs than namespaces.

Or is the suggestion to move it to job level but then only show the jobs that the acl is allowed to view. This is reasonable, but I'd be confused if I pass all_namespaces=true but got only a subset.

Copy link
Contributor

@cgbaker cgbaker May 19, 2020

Choose a reason for hiding this comment

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

The latter.

but I'd be confused if I pass all_namespaces=true but got only a subset.

That's exactly the behavior of GET /namespaces; the list of namespaces is filtered by ACL. I would not be confused; it's what I would expect. Regardless, that's what documentation is for. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll update it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll go further and argue that filtering is more consistent. It means that GET /jobs?all_namespaces=true is equivalent to GET /jobs | filter(_.Namespace in GET /namespaces).

Without a filtering approach, users have the situation where GET /namespaces returns a list of namespaces and GET /job?all_namespaces=true returns 403, so that they're required to loop over GET /jobs for all namespaces returns by GET /namespaces; this seems to me the exact situation that this modification is intended to avoid.

Copy link
Contributor

Choose a reason for hiding this comment

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

(answered at the same time, didn't mean to pile on)

@@ -30,6 +30,12 @@ The table below shows this endpoint's support for
- `prefix` `(string: "")` - Specifies a string to filter jobs on based on
an index prefix. This is specified as a query string parameter.

- `all_namespaces` `(bool: false)` - Specifies whether to return the all
known jobs across all namespaces. When set to `true`, the list stubs will
Copy link
Contributor

Choose a reason for hiding this comment

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

GitHub doesn't seem to let me make comments/recommendations on unchanged code :/, but I'm not keen on the idea that all_namespaces controls whether ListStub.Namespace is populated. this means, e.g., that code consuming the list of stubs has to know whether or not it was generated with all_namespaces == true. why not modify Job.Stub() to always set JobListStub.Namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered adding namespace on the stub - but worried about the increased size and we've been resisting adding more. Also noticed that we already noticed Job.Summary.Namespaces is already always populated.

In one sense, it's already a redundant field but I added it anyway because I found Job.Summary.Namespace a bit odd considering namespace is primarily a field on job rather than the summary.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool. i didn't notice that namespace was already in JobSummary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW - I was mostly explaining my rationale but I'm still open to adding Namespace field indiscriminately mostly for purity/beauty prospective if someone advocates for it :). I just don't know how resistant we are to adding more fields here.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, i agree. i think the presence in JobSummary (presumably, to support GET /job/:id:summary) perhaps argues against putting it in the list stub at all.

i'd be curious to see what other folks think.

@@ -4105,6 +4106,7 @@ type JobListStub struct {
ID string
ParentID string
Name string
Namespace string `json:",omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/hashicorp/nomad/blob/master/api/jobs.go#L866
api.JobListStub should be updated as well, for api users.

@cgbaker
Copy link
Contributor

cgbaker commented May 19, 2020

note, we'll be following this pattern to implement the same capability for GET /scaling/policies

@robloxrob
Copy link

Thank you!

@notnoop notnoop merged commit 65937ff into master Jun 1, 2020
@notnoop notnoop deleted the f-jobs-list-across-nses branch June 1, 2020 01:28
@github-actions
Copy link

github-actions bot commented Jan 4, 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 4, 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.

3 participants