1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Save endpoint config only if endpoint creation succeeds

- Currently it is being save upfront...

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2016-01-25 11:14:29 -08:00 committed by Tibor Vass
parent 08ca18b59d
commit 61943d54aa
3 changed files with 21 additions and 7 deletions

View file

@ -265,7 +265,7 @@ func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork
}
// BuildCreateEndpointOptions builds endpoint options from a given network.
func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error) {
func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *network.EndpointSettings) ([]libnetwork.EndpointOption, error) {
var (
portSpecs = make(nat.PortSet)
bindings = make(nat.PortMap)
@ -278,7 +278,7 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network) ([]
createOptions = append(createOptions, libnetwork.CreateOptionAnonymous())
}
if epConfig, ok := container.NetworkSettings.Networks[n.Name()]; ok {
if epConfig != nil {
ipam := epConfig.IPAMConfig
if ipam != nil && (ipam.IPv4Address != "" || ipam.IPv6Address != "") {
createOptions = append(createOptions,

View file

@ -775,11 +775,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
controller := daemon.netController
if endpointConfig != nil {
container.NetworkSettings.Networks[n.Name()] = endpointConfig
}
createOptions, err := container.BuildCreateEndpointOptions(n)
createOptions, err := container.BuildCreateEndpointOptions(n, endpointConfig)
if err != nil {
return err
}
@ -797,6 +793,10 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
}
}()
if endpointConfig != nil {
container.NetworkSettings.Networks[n.Name()] = endpointConfig
}
if err := daemon.updateEndpointNetworkSettings(container, n, ep); err != nil {
return err
}

View file

@ -1333,3 +1333,17 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *check.C) {
_, _, err = dockerCmdWithError("exec", "c2.net1", "ping", "-c", "1", "c1.net1.br.net1.google.com")
c.Assert(err, check.NotNil)
}
func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *check.C) {
dockerCmd(c, "run", "-d", "--name=bb", "busybox", "top")
c.Assert(waitRun("bb"), check.IsNil)
ns0, _ := dockerCmd(c, "inspect", "--format='{{ .NetworkSettings.Networks.bridge }}'", "bb")
// A failing redundant network connect should not alter current container's endpoint settings
_, _, err := dockerCmdWithError("network", "connect", "bridge", "bb")
c.Assert(err, check.NotNil)
ns1, _ := dockerCmd(c, "inspect", "--format='{{ .NetworkSettings.Networks.bridge }}'", "bb")
c.Assert(ns1, check.Equals, ns0)
}