Add local address autodetection on swarm init#28221
Add local address autodetection on swarm init#28221aaronlehmann merged 1 commit intomoby:masterfrom aboch:ala
Conversation
daemon/cluster/cluster.go
Outdated
There was a problem hiding this comment.
Is it correct to override listenHost like this? If the user asked to bind to 0.0.0.0, shouldn't we still do so? I would think only localAddr needs to be overridden.
There was a problem hiding this comment.
In this case it is, because if the the user asked to bind to 0.0.0.0 explicitly or did not specify --listen-addr (in both cases listenHost==0.0.0.0 so true == net.ParseIP(localAddr).IsUnspecified()), we would fail the swarm init (because of the adv addr locality).
If listenHost==0.0.0.0, and --advertise-addr is not local, we currently ask the user to specify a --listen-addr, in other words a listenHost. Therefore here we are sparing the user from specifying a --listen-addr when we can find one by ourselves.
It is true we could just take care of the local address, and my first implementation was only doing that, but I felt it was safer, more predictable to fill in what currently we ask the user to fill, which is the --listen-addr, and keep current logic where the local address is the listen address (when available).
So that the addresses libnetwork receive are consistent either when --listen-addr is specified by user or when we need user to specify the --listen-addr but we can do it ourselves for ease of use.
There was a problem hiding this comment.
I see the logic but it feels wrong to me to bind to an automatically detected IP even if the user explicitly passed --listen-addr 0.0.0.0:<port>.
There was a problem hiding this comment.
Understand. But even today user is not allowed to pass --listen-addr 0.0.0.0:<port> and --advertise-addr=<non local address> combination.
The change takes effect only when adv addr is non local and we need a specific local address for the ipsec tunnels.
I probably don't see it, but if that seems the proper change to be done, I can take care of filling in only the local address. Let me know (only thing I will only be able to take care of it late tonight only, at the park now). Thanks.
|
Nice! Thanks for working on this. |
|
@aaronlehmann Changed to only set the local address. Tested it on aws. PTAL when you get a chance. |
|
LGTM |
|
LGTM @aboch is it possible to write a integration-test for this ? |
|
@mavenugo It is a bit tricky, because in order to test this scenario I need traffic to flow via two docker hosts (whatever their abstraction is in integ framework) with 1 to 1 NAT between their internal address and external address. So that I can create a 2 tasks service or attach two containers so that the ipsec tunnels are programmed, then finally run traffic among containers. I would prefer this functionality to go in in time for 1.13 and investigate later if/how a meaningful test for this can be done. |
|
@aboch okay. Is it possible to add a test without checking for the actual data-path ? I mean, we could do |
|
@mavenugo Oh, I see, just to test the swarm init go through. That should be possible. Let me take a look. |
|
@mavenugo Added the test. Verified it does not pass on master. Thanks. |
|
When I run the integ test locally it works, it is able to detect a system address. But it fails on jenkins: |
|
It looks like a leaked interface from a previous test is causing this (thanks @tonistiigi for leading me to the logs): Given the test is not really adding much, I am suggesting to remove it for now. |
- when advertise-addr is not local and listen-addr is not specified Signed-off-by: Alessandro Boch <aboch@docker.com>
|
@aboch yes. agreed. pls do so. |
- What I did
Added local address auto detection during
swarm initwhen--advertise-addris a non local address.It is the same best-effort auto detection logic which is being used when advertise address is not specified.
- How to verify it
Form a cluster on AWS with
swarm init --advertise-addr <this VM public IP>andswarm join ... --advertise-addr <this VM public IP>Create a service over an encrypted overlay network and make sure tasks can talk to other nodes' tasks. Run a container on the attachable network and make sure it can access the service.
Fixes #27647
- A picture of a cute animal (not mandatory but encouraged)
