-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 catalog CLI functions #3204
Conversation
|
||
List all datacenters: | ||
|
||
$ consul catalog datacenters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ should these all be "actions" instead? Like list-datacenters
and list-nodes
? In the consul kv
CLI, everything is an action (verb), but list-datacenters
seems blah to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just datacenters
is fine since the only datacenter-related thing you can do is list them right now, if we added other actions later it could become consul catalog datacenters list
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I kind of like the verbs (like https://www.consul.io/docs/commands/operator/area.html), we could start out that way so we get help with the top-level command showing help and we've got a spot for more things later like deregister
:
consul catalog datacenters list
consul catalog nodes list
consul catalog services list
If we start out with consul catalog datacenters
running list, there's no where to park the help for the datacenters
subcommands later, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, that was my fear. I just also fear that we are going too deep (queue Inception gif). I find CLIs challenging to reason about beyond the third level, which is why I like the kv CLI
consul kv [action]
That's why I suggested
consul catalog list-datacenters
since then list is a verb. Otherwise, we have inconsistency where some CLI commands are "namespace verb" and others are "namespace noun verb".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - I can live with that - I do like verbs and flattening the verbs into one level of consul catalog <verb>
seems like a good compromise.
command/catalog_datacenters.go
Outdated
"github.com/mitchellh/cli" | ||
) | ||
|
||
var _ cli.Command = (*CatalogDatacentersCommand)(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyhavlov I found this on the Internets as a better way to test is something implements an interface. We used to do this in test, but this will fail at build time if the interfaces don't match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find, that's a lot better than having to run a test
command/catalog_nodes.go
Outdated
return strings.TrimSpace(helpText) | ||
} | ||
|
||
func (c *CatalogNodesCommand) Run(args []string) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a WIP, and I wanted to solicit feedback on the API/UX here.
I can see a few possible ways this could go:
consul catalog nodes
returns a list of node ids (no other data), and then-detailed
returns a more tabular like (likeconsul kv get -detailed
)- should it be node ids or node names?
- should it be node names falling back to node ids?
consul catalog nodes
returns everything in tabular format except tagged addrs, meta, and create/modify indexes
Thoughts? I think I like the first one, since it allows for better composition into other resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having it show tabular format similar to members
(option 2) could still feed into cut
or some other utility, but I don't really have a preference here, as long as there's a -detailed
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was kind of expecting consul members
-like table output for this, too, since there's a lot of info vs consul kv get -detailed
. Maybe something like:
consul catalog node list
maybe a table of: node name, node id, addressconsul catalog node info -node=<name or id>
does thekv -detailed
kind of thing
Still kind of thinking about this one...
command/catalog_nodes.go
Outdated
func prettyNode(w io.Writer, node *api.Node) error { | ||
tw := tabwriter.NewWriter(w, 0, 2, 6, ' ', 0) | ||
fmt.Fprintf(tw, "ID\t%s\n", node.ID) | ||
if node.Node != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this ever be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you try to start a node with a blank node name, it'll default to the hostname, so I don't think this should ever be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good - added some thoughts!
|
||
List all datacenters: | ||
|
||
$ consul catalog datacenters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I kind of like the verbs (like https://www.consul.io/docs/commands/operator/area.html), we could start out that way so we get help with the top-level command showing help and we've got a spot for more things later like deregister
:
consul catalog datacenters list
consul catalog nodes list
consul catalog services list
If we start out with consul catalog datacenters
running list, there's no where to park the help for the datacenters
subcommands later, for example.
command/catalog_nodes.go
Outdated
|
||
func (c *CatalogNodesCommand) Help() string { | ||
helpText := ` | ||
Usage: consul catalog datacenters [options] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale.
command/catalog_nodes.go
Outdated
return strings.TrimSpace(helpText) | ||
} | ||
|
||
func (c *CatalogNodesCommand) Run(args []string) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was kind of expecting consul members
-like table output for this, too, since there's a lot of info vs consul kv get -detailed
. Maybe something like:
consul catalog node list
maybe a table of: node name, node id, addressconsul catalog node info -node=<name or id>
does thekv -detailed
kind of thing
Still kind of thinking about this one...
0177c9d
to
5c38350
Compare
@slackpad @kyhavlov @magiconair @preetapan I think this is ready for real review now! 😄 |
Also, the more I'm typing and working with these, I think
Feels a lot better than
I've been using this pretty regularly for about a week, and I don't think |
@sethvargo that's fair - i'd be ok to drop the "list-" prefix as it does look ugly. We could put verbs for future actions and mix them, which seems workable:
|
Okay - updated |
This was just taking up bytes given the newer flag format
This isn't exactly "pretty". It's much easier to use the same data structure, so we convert the unmatched data type to the proper one.
It's possible to generate an empty node ID using the catalog/register endpoint.
500d50c
to
ef4d322
Compare
This actually calls up to the servers, so want to not include "agent" here.
I am restricting the first pass to "readonly" (no register or deregister functionality).
/cc @hashicorp/consul