Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Conversation

@wsong
Copy link
Contributor

@wsong wsong commented Apr 30, 2019

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

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "fix_endpoints_config2" [email protected]:wsong/swarm.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@wsong wsong force-pushed the fix_endpoints_config2 branch from 2e5d2af to 05ad851 Compare April 30, 2019 16:35
@wsong wsong force-pushed the fix_endpoints_config2 branch from 05ad851 to 8b1e4e7 Compare April 30, 2019 16:37
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")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@dperny
Copy link
Contributor

dperny commented May 3, 2019

OK yes that makes sense.

I feel like the CI should not be failing on every single version, though.

@wsong
Copy link
Contributor Author

wsong commented May 3, 2019

@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.

@dperny
Copy link
Contributor

dperny commented May 3, 2019

ok, that's good enough for me. i don't have write permissions, though.

for networkName, v := range n.EndpointsConfig {
parts := strings.SplitN(networkName, "/", 2)
if len(parts) > 1 {
networkName = parts[1]
Copy link
Member

@thaJeztah thaJeztah May 3, 2019

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

Copy link
Contributor Author

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.

@wsong wsong force-pushed the fix_endpoints_config2 branch from 8b1e4e7 to 379adde Compare May 3, 2019 20:17
@wsong
Copy link
Contributor Author

wsong commented May 3, 2019

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

@wsong wsong force-pushed the fix_endpoints_config2 branch 2 times, most recently from 718a49f to 7f090b7 Compare May 8, 2019 16:39
Copy link
Member

@thaJeztah thaJeztah left a 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

// 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 {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done.

func TestCleanupNetworkingConfig(t *testing.T) {
networkingConfig := network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
"testnet1": &network.EndpointSettings{},
Copy link
Member

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":      {},
		},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

EndpointsConfig: map[string]*network.EndpointSettings{
"testnet1": &network.EndpointSettings{},
"nodename/testnet2": &network.EndpointSettings{},
"nodename/test/net3": &network.EndpointSettings{},
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// EngineNames returns the names of all the engines in the cluster.
func (c *Cluster) EngineNames() []string {
ret := []string{}
Copy link
Member

Choose a reason for hiding this comment

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

perhaps

Suggested change
ret := []string{}
ret := make([]string, len(c.engines))

Copy link
Contributor Author

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())
Copy link
Member

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

Copy link
Contributor Author

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.

@wsong wsong force-pushed the fix_endpoints_config2 branch 2 times, most recently from 27e59d3 to 84ac348 Compare May 8, 2019 17:26
…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]>
@wsong wsong force-pushed the fix_endpoints_config2 branch from 84ac348 to 7c91dc7 Compare May 8, 2019 17:27
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah
Copy link
Member

17.06 is green now; let's merge

@thaJeztah thaJeztah merged commit 9392e47 into docker-archive:master May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants