(Re)create endpoints in a stable order#46036
(Re)create endpoints in a stable order#46036akerouanton wants to merge 3 commits intomoby:masterfrom
Conversation
Signed-off-by: Albin Kerouanton <[email protected]>
55da585 to
b10607d
Compare
| // may not be available at the time. At the same time, inside daemon `ConnectContainerToNetwork` | ||
| // does the ambiguity check anyway. Therefore, passing the name to daemon would be enough. | ||
| return n.backend.ConnectContainerToNetwork(connect.Container, vars["id"], connect.EndpointConfig) | ||
| return n.backend.ConnectContainerToNetwork(connect.Container, vars["id"], connect.EndpointConfig, true) |
There was a problem hiding this comment.
I'm not sure whether this should be set to false for API < 1.44 🤔
There was a problem hiding this comment.
If the current order is randomised by go (thus "undefined"), then applying things in the correct order would make it equally "undefined" (just 100% more predictable), so I think it's fine to make it independent of the API version.
The Priority FIELD should not be looked at for older API versions (when creating).
There was a problem hiding this comment.
The Priority FIELD should not be looked at for older API versions (when creating).
Mh, I'm assuming Priority is 0 for older API versions but that might be only for our Go client 🤔 Maybe I should force it to 0 for older versions.
|
|
||
| // ConnectToNetwork connects a container to a network | ||
| func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName string, endpointConfig *networktypes.EndpointSettings) error { | ||
| func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName string, endpointConfig *networktypes.EndpointSettings, autoPriority bool) error { |
There was a problem hiding this comment.
Looks like autoPriority is unused?
| } | ||
| } | ||
|
|
||
| joinOptions = append(joinOptions, libnetwork.JoinOptionPriority(priority)) |
There was a problem hiding this comment.
We're passing priority here, but wouldn't networkSettings.Networks[n.Name()] (which is an EndpointSettings) already have a Priority field?
(haven't checked how/where that's set though; so many levels of indirection 😂)
There was a problem hiding this comment.
Nope, the networkSettings here is github.com/docker/docker/daemon/network.Settings, whereas I added Priority to github.com/docker/docker/api/types/network.EndpointSettings.
It's a bit confusing in my opinion. I have some comments laying somewhere in a stash, I need to open up a PR to add them, at least it'd help to easily know who's who.
b10607d to
2d3308e
Compare
The newly introduced Priority API field is now used to create the container endpoints in descending Priority order. Also the `JoinOptionPriority()` is now used to make sure the interface names are stable over restarts. Signed-off-by: Albin Kerouanton <[email protected]>
Without this change, clients would have to call ContainerInspect before NetworkConnect to set the right Priority on the endpoint. And this wouldn't be without potential timing issues. As such, this change totally ignores the client-provided Priority value and erase it with a computed value. Signed-off-by: Albin Kerouanton <[email protected]>
2d3308e to
72789d7
Compare
|
So, one of the failing test is checking if the default gateway and "anonymous" port mappings change whenever the container connects to a network which comes before other networks the container is connected to in the lexicographic order: And I'm pretty sure some people rely on this to set their default gateway. I need to check if that's still documented (it was at some point) and what to do next. |
|
Is there still work in progress here? Or something missing? |
|
Related to:
Fixes:
- What I did
Priorityfield toEndpointSettings;daemon.connectToNetworkare done in descending order ;NetworkConnect, thePriorityvalue is automatically computed based on the lowestPriorityminus one ;The choice to use descending over ascending order has been made to match what the Compose spec defines.
This change brings interesting advantages for end users:
- How to verify it
- Description for the changelog
Interfaces are always created in the same order and their name is stable over restarts.
- A picture of a cute animal (not mandatory but encouraged)