Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Use service server IPs from Sidecar #11

Merged
merged 8 commits into from
May 23, 2017
Merged

Conversation

mihaitodor
Copy link

@mihaitodor mihaitodor commented May 12, 2017

This is a follow-up to the conversation from here.

We want to fetch the IP addresses from Sidecar, if possible.

Also, we want to support having multiple ports exposed for the same service on the same host. This changeset appends _<port> to the service name when multiple ports are provided instead of exposing only the first port.

TODO:

  • do we want to not add the server at all if the hostname can't be resolved to an IP or should we just let Traefik deal with that?

@mihaitodor
Copy link
Author

@relistan @bparli Please have a look and let me know what you think.

@bparli
Copy link

bparli commented May 19, 2017

do we want to not add the server at all if the hostname can't be resolved to an IP or should we just let Traefik deal with that?

I'd gone back and forth on this before, but lean towards not adding it now. I think you'd argued this previously too @mihaitodor; if we can't resolve the address at this stage, the rest of the program likely won't be able to either.

@mihaitodor
Copy link
Author

OK @bparli, I updated the code.

@relistan May I go ahead and merge this changeset?

Copy link

@relistan relistan left a comment

Choose a reason for hiding this comment

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

Code looks good, some comments below.

URL: "http://" + ipAddr[0].String() + ":" + strconv.FormatInt(svc.Ports[i].Port, 10),
for _, port := range svc.Ports {
name := svc.Hostname
if len(svc.Ports) > 1 {

Choose a reason for hiding this comment

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

Let's just make them consistent and always use the port.

}

host := port.IP
if host == "" {
Copy link

@relistan relistan May 23, 2017

Choose a reason for hiding this comment

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

I don't do this in Sidecar and should, but let's be careful here to make sure we got a properly formed IP address by doing an net.ParseIP here to make sure it's a valid IP as well. We will just use the string, but the parse will tell us it's legit.

@@ -92,7 +93,37 @@ func TestSidecar(t *testing.T) {
ID: "008",
Name: "api",
Hostname: "another-aws-host",
Status: 0,
Ports: []service.Port{
service.Port{

Choose a reason for hiding this comment

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

gofmt -s on this file and it will probably remove these inner service.Port names.

Copy link
Author

Choose a reason for hiding this comment

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

Nice catch @relistan! So, it turns out that the standard goimports doesn't support the -s flag that gofmt provides. I ended up installing this 3rd party goimports to have this flag and keep using the goimports hook on save.

Choose a reason for hiding this comment

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

Yep, that's one annoyance of goimports. 💯 I'll take a look at the fork.

@@ -101,13 +132,21 @@ func TestSidecar(t *testing.T) {

backs := prov.makeBackends(states)

Choose a reason for hiding this comment

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

This seems like way too much stuff to be checking in a single test. The comments explaining all the checks are the giveaway. Even if you have to repeat the same loading of the data multiple times in separate tests, this should be broken into tests that are validating the same functionality. Just share the setup between the Convey blocks and give the So clauses a wrapper that explains what they're doing.

Copy link
Author

Choose a reason for hiding this comment

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

Good point! I'm starting to like goconvey :)

@mihaitodor
Copy link
Author

@relistan I think I covered everything. Please let me know if it's good to go now.

@relistan
Copy link

:shipit: !

@mihaitodor mihaitodor merged commit 3583069 into master May 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants