hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.91k stars 1.95k forks source link

add `-json` and `-t` options to inspection related cmds #15894

Open noahehall opened 1 year ago

noahehall commented 1 year ago

Proposal

Use-cases

List of commands missing flags

The following commands require a Nomad license, and it may not be possible to work on them without one.

The following commands are unusual in the sense they are not backed by a Go struct, so a JSON output would need to be created manually.

jrasell commented 1 year ago

Hi @noahehall and thanks for raising this. I agree and think this would be really useful, and therefore will add it to our backlog.

dttung2905 commented 1 year ago

Hi @jrasell , do you have a list of nomad cli command that we want to add -json flag? I can help out on this if you don't mind

jrasell commented 1 year ago

Hi @dttung2905, that sounds great. I have used grep -L "\-json" --exclude="*_test.go" --exclude="*_delete.go" command/*.go to get a better view of the files that could be suitable for adding the -json and t flags. All those listed, however, would not be suitable.

Those that seem like good initial candidates would be:

Please let me know if you have any questions or thoughts.

lgfa29 commented 1 year ago

I closed some issues that were related to this one. The commands mentioned in them were:

jrasell commented 1 year ago

Just wanted to post an update of some internal progress that has been made internally over the past few weeks. The following PR's have been raised to add -json and -t flags to the CLI where missing:

Thanks to @Juanadelacuesta for this work!

noahehall commented 1 year ago

@Juanadelacuesta excellent work!

BBBmau commented 1 year ago

I'm interested in contributing to Nomad, are there any other commands that could use the -json and -t flags?

I saw that acl token create is one that could use it but it seems like acl token list already accomplishes this with the flags already included.

lgfa29 commented 1 year ago

Hi @BBBmau 👋

That's awesome that you're interested in contributing to Nomad! I think any info, status, list command should have a -json and -t flag.

For create and apply commands, as the example you mentioned, it would be helpful to have these flags when the output has the generated resource, and so you can pipe its output to something else. For example, it would allow you to do something like this:

$ nomad acl token create | jq -r '.SecretID' > secret_token.txt

(for consistency, all create and apply should probably have these flags, but that's likely a bigger scope, specially since some apply commands already have a -json flag to change input parsing, but I digress 😅 )

https://github.com/hashicorp/nomad/pull/16055 already added these flags to acl token create but I updated the issue body with a more exhaustive list of commands still missing them. Feel free to pick anyone of them to work next and let us know if you need any help 🙂