Properly handle Leave by

- Removing interface from the sandbox
  - Deleting Iptable rules in the bridge driver

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-05-06 00:33:08 +00:00
parent f055e06f3a
commit ff36e97f45
2 changed files with 34 additions and 8 deletions

View file

@ -60,11 +60,12 @@ type ContainerConfiguration struct {
}
type bridgeEndpoint struct {
id types.UUID
intf *sandbox.Interface
macAddress net.HardwareAddr
config *EndpointConfiguration // User specified parameters
portMapping []netutils.PortBinding // Operation port bindings
id types.UUID
intf *sandbox.Interface
macAddress net.HardwareAddr
config *EndpointConfiguration // User specified parameters
containerConfig *ContainerConfiguration
portMapping []netutils.PortBinding // Operation port bindings
}
type bridgeNetwork struct {
@ -643,6 +644,8 @@ func (d *driver) Leave(nid, eid types.UUID, options map[string]interface{}) erro
}
func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enable bool) error {
var cc *ContainerConfiguration
network, err := d.getNetwork(nid)
if err != nil {
return err
@ -656,10 +659,15 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl
return EndpointNotFoundError(eid)
}
cc, err := parseContainerOptions(options)
if err != nil {
return err
if enable {
cc, err = parseContainerOptions(options)
if err != nil {
return err
}
} else {
cc = endpoint.containerConfig
}
if cc == nil {
return nil
}
@ -725,6 +733,11 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl
l.Disable()
}
}
if enable {
endpoint.containerConfig = cc
}
return nil
}

View file

@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/etchosts"
"github.com/docker/docker/pkg/resolvconf"
"github.com/docker/libnetwork/driverapi"
@ -275,6 +276,18 @@ func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {
n := ep.network
err := n.driver.Leave(n.id, ep.id, ep.context)
sinfo := ep.SandboxInfo()
if sinfo != nil {
sb := ep.network.ctrlr.sandboxGet(ep.container.data.SandboxKey)
for _, i := range sinfo.Interfaces {
err = sb.RemoveInterface(i)
if err != nil {
logrus.Debugf("Remove interface failed: %v", err)
}
}
}
ep.network.ctrlr.sandboxRm(ep.container.data.SandboxKey)
ep.container = nil
ep.context = nil