-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Strip off node name network prefixes in endpoint configs in networking configs #2941
Conversation
|
Please sign your commits following these rules: $ git clone -b "fix_endpoints_config2" [email protected]:wsong/swarm.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -fAmending updates the existing PR. You DO NOT need to open a new one. |
2e5d2af to
05ad851
Compare
05ad851 to
8b1e4e7
Compare
cluster/config_test.go
Outdated
| config = BuildContainerConfig(container.Config{}, container.HostConfig{}, networkingConfig) | ||
| assert.Contains(t, config.NetworkingConfig.EndpointsConfig, "testnet1") | ||
| assert.Contains(t, config.NetworkingConfig.EndpointsConfig, "testnet2") | ||
| assert.Contains(t, config.NetworkingConfig.EndpointsConfig, "test/net3") |
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.
does assert.Contains not mean that the string "nodename/testnet2" would pass the assertion?
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.
config.NetworkingConfig.EndpointsConfig is a map, so we're checking for whether or not this exact key is in the map.
|
OK yes that makes sense. I feel like the CI should not be failing on every single version, though. |
|
@dperny and I looked at the failures and it looks like most of the failures are actually from DinD failing to start. Not sure what's going on there but it seems clearly unrelated to this PR. |
|
ok, that's good enough for me. i don't have write permissions, though. |
cluster/config.go
Outdated
| for networkName, v := range n.EndpointsConfig { | ||
| parts := strings.SplitN(networkName, "/", 2) | ||
| if len(parts) > 1 { | ||
| networkName = parts[1] |
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 think this will be a backward breaking change, as I can create custom networks having a /;
docker network create foo/bar/baz
docker network ls
NETWORK ID NAME DRIVER SCOPE
5ce5654a460e bridge bridge local
81d2f269d9ff docker_gwbridge bridge local
7296e31838b7 foo/bar/baz bridge local
26d3887604d2 host host local
59e5e41d3a7b none null local
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.
Hmm, I guess we'll have to iterate through and see if parts[0] is the name of a node.
8b1e4e7 to
379adde
Compare
|
Okay, I refactored this so that we check the list of node names and make sure that the part we're stripping off is the name of a node. PTAL |
718a49f to
7f090b7
Compare
thaJeztah
left a comment
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.
overall approach SGTM. left some thoughts/suggestions
cluster/config.go
Outdated
| // user specified a Swarm classic-style network name in the endpoints config | ||
| // (i.e. <node name>/<network name>), strips off the node name so that the | ||
| // daemon will recognize the network. | ||
| func CleanupNetworkingConfig(n network.NetworkingConfig, nodeNames []string) network.NetworkingConfig { |
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.
Perhaps we should rename this to what it actually does, e.g. StripNodeNames (but also see my other comment w.r.t possibly making it a local helper function
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.
Good idea, done.
cluster/config_test.go
Outdated
| func TestCleanupNetworkingConfig(t *testing.T) { | ||
| networkingConfig := network.NetworkingConfig{ | ||
| EndpointsConfig: map[string]*network.EndpointSettings{ | ||
| "testnet1": &network.EndpointSettings{}, |
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 &network.EndpointSettings is redundant here;
EndpointsConfig: map[string]*network.EndpointSettings{
"testnet1": {},
"nodename/testnet2": {},
"nodename/test/net3": {},
"foo/test/net4": {},
},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.
Done.
cluster/config_test.go
Outdated
| EndpointsConfig: map[string]*network.EndpointSettings{ | ||
| "testnet1": &network.EndpointSettings{}, | ||
| "nodename/testnet2": &network.EndpointSettings{}, | ||
| "nodename/test/net3": &network.EndpointSettings{}, |
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.
Quite unlikely to be a problem, but might want to add a case where nodename is actually part of the network name, e.g. "nodename/nodename/net4" (which should produce nodename/net4)
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.
Done.
cluster/swarm/cluster.go
Outdated
|
|
||
| // EngineNames returns the names of all the engines in the cluster. | ||
| func (c *Cluster) EngineNames() []string { | ||
| ret := []string{} |
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.
perhaps
| ret := []string{} | |
| ret := make([]string, len(c.engines)) |
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.
Done.
api/handlers.go
Outdated
| httpError(w, err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| containerConfig.NetworkingConfig = cluster.CleanupNetworkingConfig(containerConfig.NetworkingConfig, c.cluster.EngineNames()) |
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 was a bit on the fence if we should move this into cluster.CreateContainer(); that way CreateContainer would responsible for dealing with this (and we wouldn't have to modify the Interface to add EngineNames()).
I went looking for uses of CreateContainer() and the other location it's used is in rescheduleContainers, which copies the configuration of existing containers, so in that case the nodename would be stripped twice
We could consider making it a local utility and move it here, given that it's fixing something specific to this endpoint, but happy to get your thought on that
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 think it makes sense to just strip the node names when the container configs first come into the API; as you point out, we should definitely not be stripping node names in rescheduleContainers. I'll move CleanupNetworkingConfig (aka StripNodeNames) into this file.
27e59d3 to
84ac348
Compare
…g configs Previously, if you specified something like: ``` docker run --rm \ --net=mynode/testnet --network-alias=foobar \ alpine ``` Swarm classic would fail because it would try to pass an endpoint config to the daemon with `mynode/testnet` as the network name Signed-off-by: Wayne Song <[email protected]>
84ac348 to
7c91dc7
Compare
thaJeztah
left a comment
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, thanks!
|
17.06 is green now; let's merge |
Previously, if you specified something like:
Swarm classic would fail because it would try to pass an endpoint config to the
daemon with
mynode/testnetas the network name