Merge pull request #14163 from mrjana/cnm_integ

Fix endpoint leave failure for --net=host mode
This commit is contained in:
Alexander Morozov 2015-06-25 10:17:03 -07:00
commit e0cfe36b8e
5 changed files with 66 additions and 23 deletions

View File

@ -1003,33 +1003,47 @@ func (container *Container) ReleaseNetwork() {
return return
} }
err := container.daemon.netController.LeaveAll(container.ID)
if err != nil {
logrus.Errorf("Leave all failed for %s: %v", container.ID, err)
return
}
eid := container.NetworkSettings.EndpointID eid := container.NetworkSettings.EndpointID
nid := container.NetworkSettings.NetworkID nid := container.NetworkSettings.NetworkID
container.NetworkSettings = &network.Settings{} container.NetworkSettings = &network.Settings{}
// In addition to leaving all endpoints, delete implicitly created endpoint if nid == "" || eid == "" {
if container.Config.PublishService == "" && eid != "" && nid != "" { return
}
n, err := container.daemon.netController.NetworkByID(nid) n, err := container.daemon.netController.NetworkByID(nid)
if err != nil { if err != nil {
logrus.Errorf("error locating network id %s: %v", nid, err) logrus.Errorf("error locating network id %s: %v", nid, err)
return return
} }
ep, err := n.EndpointByID(eid) ep, err := n.EndpointByID(eid)
if err != nil { if err != nil {
logrus.Errorf("error locating endpoint id %s: %v", eid, err) logrus.Errorf("error locating endpoint id %s: %v", eid, err)
return return
} }
switch {
case container.hostConfig.NetworkMode.IsHost():
if err := ep.Leave(container.ID); err != nil {
logrus.Errorf("Error leaving endpoint id %s for container %s: %v", eid, container.ID, err)
return
}
default:
if err := container.daemon.netController.LeaveAll(container.ID); err != nil {
logrus.Errorf("Leave all failed for %s: %v", container.ID, err)
return
}
}
// In addition to leaving all endpoints, delete implicitly created endpoint
if container.Config.PublishService == "" {
if err := ep.Delete(); err != nil { if err := ep.Delete(); err != nil {
logrus.Errorf("deleting endpoint failed: %v", err) logrus.Errorf("deleting endpoint failed: %v", err)
} }
} }
} }
func disableAllActiveLinks(container *Container) { func disableAllActiveLinks(container *Container) {

View File

@ -18,7 +18,7 @@ clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://gith
clone hg code.google.com/p/gosqlite 74691fb6f837 clone hg code.google.com/p/gosqlite 74691fb6f837
#get libnetwork packages #get libnetwork packages
clone git github.com/docker/libnetwork 1aaf1047fd48345619a875184538a0eb6c6cfb2a clone git github.com/docker/libnetwork 82a1f5634904b57e619fd715ded6903727e00143
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4 clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4

View File

@ -2820,6 +2820,22 @@ func (s *DockerSuite) TestRunNetHost(c *check.C) {
} }
} }
func (s *DockerSuite) TestRunNetHostTwiceSameName(c *check.C) {
testRequires(c, SameHostDaemon)
cmd := exec.Command(dockerBinary, "run", "--rm", "--name=thost", "--net=host", "busybox", "true")
out2, _, err := runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err, out2)
}
cmd = exec.Command(dockerBinary, "run", "--rm", "--name=thost", "--net=host", "busybox", "true")
out2, _, err = runCommandWithOutput(cmd)
if err != nil {
c.Fatal(err, out2)
}
}
func (s *DockerSuite) TestRunNetContainerWhichHost(c *check.C) { func (s *DockerSuite) TestRunNetContainerWhichHost(c *check.C) {
testRequires(c, SameHostDaemon) testRequires(c, SameHostDaemon)

View File

@ -68,6 +68,10 @@ func Build(path, IP, hostname, domainname string, extraContent []Record) error {
// Add adds an arbitrary number of Records to an already existing /etc/hosts file // Add adds an arbitrary number of Records to an already existing /etc/hosts file
func Add(path string, recs []Record) error { func Add(path string, recs []Record) error {
if len(recs) == 0 {
return nil
}
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
return err return err
@ -91,6 +95,10 @@ func Add(path string, recs []Record) error {
// Delete deletes an arbitrary number of Records already existing in /etc/hosts file // Delete deletes an arbitrary number of Records already existing in /etc/hosts file
func Delete(path string, recs []Record) error { func Delete(path string, recs []Record) error {
if len(recs) == 0 {
return nil
}
old, err := ioutil.ReadFile(path) old, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
return err return err

View File

@ -416,6 +416,11 @@ func (n *network) updateSvcRecord(ep *endpoint, isAdd bool) {
} }
n.Unlock() n.Unlock()
// If there are no records to add or delete then simply return here
if len(recs) == 0 {
return
}
var epList []*endpoint var epList []*endpoint
n.WalkEndpoints(func(e Endpoint) bool { n.WalkEndpoints(func(e Endpoint) bool {
cEp := e.(*endpoint) cEp := e.(*endpoint)