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

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

Open
15 tasks
noahehall opened this issue Jan 26, 2023 · 8 comments
Open
15 tasks

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

noahehall opened this issue Jan 26, 2023 · 8 comments
Labels
good first issue stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli type/enhancement

Comments

@noahehall
Copy link

noahehall commented Jan 26, 2023

Proposal

  • having -json output for inspection cmds (e.g. nomad server members) would be awesome
  • e.g. nomad node status -verbose -json can be piped to jq and drilled down to retrieve info,
    • but many cmds dont have the -json option

Use-cases

  • support scripting and automation without resorting to awk/sed

List of commands missing flags

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

  • nomad license get
  • nomad sentinel list
  • nomad sentinel read

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.

  • nomad alloc fs (file stat and directory output)
  • nomad operator raft info
@jrasell
Copy link
Member

jrasell commented Jan 26, 2023

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

@jrasell jrasell added theme/cli good first issue stage/accepted Confirmed, and intend to work on. No timeline committment though. labels Jan 26, 2023
@dttung2905
Copy link
Contributor

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
Copy link
Member

jrasell commented Jan 31, 2023

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:

  • command/alloc_checks.go
  • command/namespace_status.go
  • command/quota_inspect.go
  • command/quota_status.go
  • command/sentinel_list.go
  • command/sentinel_read.go
  • command/server_members.go
  • command/sentinel_list.go
  • command/sentinel_read.go

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

@lgfa29 lgfa29 changed the title add -json option to inspection related cmds add -json and -t options to inspection related cmds Feb 3, 2023
@lgfa29
Copy link
Contributor

lgfa29 commented Feb 3, 2023

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

  • nomad acl token create
  • nomad node status
  • nomad alloc status

@jrasell
Copy link
Member

jrasell commented Mar 16, 2023

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
Copy link
Author

@Juanadelacuesta excellent work!

@BBBmau
Copy link

BBBmau commented Jun 26, 2023

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
Copy link
Contributor

lgfa29 commented Jul 4, 2023

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 😅 )

#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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli type/enhancement
Projects
Status: Needs Roadmapping
Development

No branches or pull requests

6 participants