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: add operator api command #10808

Merged
merged 12 commits into from
Mar 2, 2022
Merged

cli: add operator api command #10808

merged 12 commits into from
Mar 2, 2022

Conversation

schmichael
Copy link
Member

@schmichael schmichael commented Jun 23, 2021

Add a new nomad operator api <endpoint> command to ease query Nomad's HTTP API. All of the normal CLI parameters are supported (eg -token or -region) as are the regular environment variables (eg NOMAD_TOKEN or NOMAD_REGION).

For production clusters with ACLs, mTLS, and federation, manually constructing the proper curl command for accessing the Nomad HTTP API is a lot of work. This aims to ease that.

The new ?filter=... query parameter added in #12076 is also tricky to use via curl because it usually requires URL encoding the filter query. This subcommand also supports adding filters to arbitrary APIs.

Future work:

I didn't alias nomad operator ... to nomad op ... commands. Not sure it's worth it since most people probably have tab completion enabled? Still might be worth it for docs and scripts.

Probably add a million other little features (-stale, -pretty, -wait, etc) Not sure where to draw the line for the MVP.

Comment on lines 38 to 41
--cacert "$HOME/.nomad/ca.pem" \
--cert "$HOME/.nomad/client.pem" \
--key "$HOME/.nomad/client-key.pem" \
--connect-to "client.global.nomad:4646:remote.client123.internal:4646" \
Copy link
Member Author

Choose a reason for hiding this comment

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

To be a fair comparison I should probably reference the environment variables when possible.

--connect-to is the really difficult one as it requires plucking the actual address out of $NOMAD_ADDR. Not impossible, but not trivial interpolation like everything else.

Still... this entire Go command could be replaced by a fairly trivial bash function for people to include in their profiles similar to autocompletion. Obviously that would require bash (not guaranteed on Windows) and curl to be installed.

Trimmed spaces around header values.

Fixed method getting forced to GET.
Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

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

Some random suggestions

command/operator_api.go Outdated Show resolved Hide resolved
website/data/docs-nav-data.json Outdated Show resolved Hide resolved
command/operator_api.go Show resolved Hide resolved
command/operator_api.go Outdated Show resolved Hide resolved
command/operator_api.go Outdated Show resolved Hide resolved
command/operator_api.go Show resolved Hide resolved
command/operator_api.go Outdated Show resolved Hide resolved
command/operator_api.go Outdated Show resolved Hide resolved
We don't want people to expect stable error codes for errors, and I
don't think these were useful for scripts anyway.
@vercel vercel bot temporarily deployed to Preview – nomad February 26, 2022 00:24 Inactive
Co-authored-by: Seth Hoenig <seth.a.hoenig@gmail.com>
Copy link
Contributor

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

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

Additional random suggestions. This command is awesome 🎉

command/operator_api.go Show resolved Hide resolved

[curl]: https://curl.se/
[envvars]: /docs/commands#environment-variables
[jobs]: /api-docs/jobs
Copy link
Contributor

@lgfa29 lgfa29 Mar 1, 2022

Choose a reason for hiding this comment

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

The layout for this page looks different from the other commands. There're usually structured like:

Command: operator api
...
Usage
...
General Options
...
API Options
...
Output
...
Examples

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Fixed it up but left out Output. It seems to be often left out and is likely mostly redundant with Examples?

Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link

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 Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
theme/api HTTP API and SDK issues theme/cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants