-
Notifications
You must be signed in to change notification settings - Fork 32
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 CONSUL_DATACENTER_NAME env #46
Add CONSUL_DATACENTER_NAME env #46
Conversation
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.
Tested locally and default still works. I haven't run multi-DC yet though.
bin/consul-manage
Outdated
@@ -8,6 +8,9 @@ set -eo pipefail | |||
preStart() { | |||
_log "Updating consul advertise address" | |||
sed -i "s/CONTAINERPILOT_CONSUL_IP/${CONTAINERPILOT_CONSUL_IP}/" /etc/consul/consul.hcl | |||
|
|||
_log "Updating consul datacenter name" | |||
sed -i "s/CONSUL_DATACENTER_NAME/${CONSUL_DATACENTER_NAME:-dc1}/" /etc/consul/consul.hcl |
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 like configuring via environment variable, I think it makes sense here. Do we even need to do anything with metadata mentioned in #23?
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.
The environment variable make it straightforward to manually set the datacenter and makes testing and iteration easier, but it doesn't incorporate the automatic datacenter detection that seems to be described in #23.
I can address that part of #23 if we can decide on how it would be triggered compared to the method implemented in this PR for manual DC specification.
Options seem to include:
CONSUL_DATACENTER_NAME=*AGREED UPON STATIC VALUE*
is checked specifically inpreStart
and triggers a metadata check if it matches. Anything but the static value would be assumed to be a manually-specified DCCONSUL_DATACENTER_AUTODETECT=triton
would invoke triton-specific attempts to discover the current datacenter and allow for future implementations for other cloud providersCONSUL_DATACENTER_AUTODETECT=1
would attempt to check different methods of discovering the current datacenter, though involve more "magic" (i.e. brittle or potentially-unexpected behavior)CONSUL_DATACENTER_AUTODETECT_TRITON=1
would invoke triton-specific attempts to discover the current datacenter, establishing the pattern for other providers to user their own envs- something else?
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 agree, and the env var satisfies non-Triton use cases. I wasn't entirely set on using metadata but we could marry the two ideas for convenience.
- Use
CONSUL_DATACENTER_NAME
to manually set/force the datacenter name. - If env var isn't present AND we have
/native/usr/sbin/mdata-get
then poll metadata forsdc:datacenter_name
. - Finally, use the default
dc1
if none of the above conditions gave us a custom value.
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.
Falling back to automatic detection seems like the best option for ease-of-use, great suggestion!
I'll include the steps taken in the README
so users can see how it'll work without having to dig into the source.
This should be ready to merge now. |
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.
LGTM
Breaking this out helped review but I think we can close this and merge it in with #48. Thoughts? |
There's an issue with #48 that's holding it up but this PR should be fine to merge on it's own. I'll add a comment there about what's pending. |
Confirmed new env var locally and default as well as non-default data center names are configured. |
Resolves #23
The environment variable in
local-compose.yml
is redudant with the bash default but calls out to users that it can be changed. Commenting it out is another option.Feedback appreciated.