mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Handle NetworkDettach for the case of network-id
When a container is attached to an "--attachable" network, it strictly forms the attacherKey using either the network-id or network-name because at the time of attachment, the daemon may not have the network downloaded locally from the manager. Hence, when the NetworkDettach is called, it should use either network-name or network-id. This fix addresses the missing network-id based dettachment case. Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
f54339dfea
commit
5f17e0f6c9
2 changed files with 35 additions and 1 deletions
|
@ -793,7 +793,10 @@ func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n li
|
|||
|
||||
if daemon.clusterProvider != nil && n.Info().Dynamic() && !container.Managed {
|
||||
if err := daemon.clusterProvider.DetachNetwork(n.Name(), container.ID); err != nil {
|
||||
logrus.Warnf("error detaching from network %s: %v", n, err)
|
||||
logrus.Warnf("error detaching from network %s: %v", n.Name(), err)
|
||||
if err := daemon.clusterProvider.DetachNetwork(n.ID(), container.ID); err != nil {
|
||||
logrus.Warnf("error detaching from network %s: %v", n.ID(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -891,6 +894,9 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
|
|||
if daemon.clusterProvider != nil && nw.Info().Dynamic() && !container.Managed {
|
||||
if err := daemon.clusterProvider.DetachNetwork(nw.Name(), container.ID); err != nil {
|
||||
logrus.Warnf("error detaching from network %s: %v", nw.Name(), err)
|
||||
if err := daemon.clusterProvider.DetachNetwork(nw.ID(), container.ID); err != nil {
|
||||
logrus.Warnf("error detaching from network %s: %v", nw.ID(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,6 +295,34 @@ func (s *DockerSwarmSuite) TestSwarmContainerEndpointOptions(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "testnet")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
networkID := strings.TrimSpace(out)
|
||||
|
||||
out, err = d.Cmd("run", "-d", "--net", networkID, "busybox", "top")
|
||||
c.Assert(err, checker.IsNil)
|
||||
cID := strings.TrimSpace(out)
|
||||
d.waitRun(cID)
|
||||
|
||||
_, err = d.Cmd("rm", "-f", cID)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out, err = d.Cmd("network", "rm", "testnet")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
checkNetwork := func(*check.C) (interface{}, check.CommentInterface) {
|
||||
out, err := d.Cmd("network", "ls")
|
||||
c.Assert(err, checker.IsNil)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
waitAndAssert(c, 3*time.Second, checkNetwork, checker.Not(checker.Contains), "testnet")
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmRemoveInternalNetwork(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue