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 CONSUL_DATACENTER_NAME env #46

Conversation

tjcelaya
Copy link
Contributor

@tjcelaya tjcelaya commented Dec 7, 2017

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.

@tjcelaya tjcelaya changed the title Resolve #23 by adding CONSUL_DATACENTER_NAME env Add CONSUL_DATACENTER_NAME env Dec 7, 2017
Copy link
Contributor

@jwreagor jwreagor left a 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.

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

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?

Copy link
Contributor Author

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 in preStart and triggers a metadata check if it matches. Anything but the static value would be assumed to be a manually-specified DC
  • CONSUL_DATACENTER_AUTODETECT=triton would invoke triton-specific attempts to discover the current datacenter and allow for future implementations for other cloud providers
  • CONSUL_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?

Copy link
Contributor

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 for sdc:datacenter_name.
  • Finally, use the default dc1 if none of the above conditions gave us a custom value.

Copy link
Contributor Author

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.

@tjcelaya
Copy link
Contributor Author

This should be ready to merge now.

tjcelaya added a commit to tjcelaya/autopilotpattern-consul that referenced this pull request Dec 11, 2017
Copy link
Contributor

@jwreagor jwreagor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jwreagor
Copy link
Contributor

Breaking this out helped review but I think we can close this and merge it in with #48. Thoughts?

@tjcelaya
Copy link
Contributor Author

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.

@jwreagor
Copy link
Contributor

Confirmed new env var locally and default as well as non-default data center names are configured.

@jwreagor jwreagor merged commit eff97e4 into autopilotpattern:master Dec 15, 2017
@tjcelaya tjcelaya deleted the enhancement/23-data-center-name-in-config-file branch December 15, 2017 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants