-
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
cli: add services register
and deregister
#4732
Conversation
We require this change to support struct to struct decoding.
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 looks awesome!
I have one feature request that I think would be easy to add but can be done later: allow reading JSON/HCL service defintion from STDIN, perhaps using the convention that -
as a file name indicates stdin.
This would be really useful when using this to generate complex registrations (e.g. connect proxies with upstreams) from scripts - you can just echo and pipe rather than having to create temp files or names pipes and clean them up again.
I really missed this in envoy
in the current envoy
command work - if envoy supported this for bootstrap it would make that wrapper tool way cleaner - no passing secrets through filesystem or CLI args etc. Note that our service definitions can also contain ACL tokens so providing a more secure way to pass them from a config generating script rather than writing to a temp file is just as relevant here.
}, | ||
}, | ||
}, | ||
}, |
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.
When f-envoy
lands it might be worth adding explicit test cases for connect proxys (including upstreams etc) and sidecar services.
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.
Absolutely, that's also why I prepped the table test. :D
} | ||
|
||
if err := client.Agent().ServiceDeregister(id); err != nil { | ||
c.UI.Error(fmt.Sprintf("Error registering service %q: %s", |
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.
Why %q
for a string? Not a big deal just wondering.
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 it makes for cleaner output to the user to see a quoted string, it also helps in cases where there are spaces (a service name shouldn't have spaces but just in general). So usually when erroring out to the user or even logging (w/o hclog) I use %q
in places I'd otherwise use %s
.
This PR adds the commands
consul services register
andconsul services deregister
for registering and deregistering services respectively against the local agent API. These commands operate in a batch fashion, making it easy for scripts, hooks, etc.Both commands accept both flags to identify services as well as standard Consul configurations. This makes it easy since a standard Consul service definition in HCL or JSON can be used directly with this command without changes.
Mapstructure Update
This PR also contains a vendor update to mapstructure to bump it to v1.1.1. This has important changes that make it easy to map the
structs.ServiceDefinition
to anapi.AgentServiceRegistration
mostly automatically.