Skip to content

Commit

Permalink
Merge pull request #1473 from shaloulcy/network_not_found
Browse files Browse the repository at this point in the history
bugfix: network not found
  • Loading branch information
allencloud authored Jun 21, 2018
2 parents 6377fbf + 8eae5bb commit 8b1f8f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 4 additions & 6 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,17 @@ func (d *Daemon) Run() error {
}
d.containerMgr = containerMgr

if err := containerMgr.Restore(ctx); err != nil {
return err
}

networkMgr, err := internal.GenNetworkMgr(d.config, d)
if err != nil {
return err
}
d.networkMgr = networkMgr
containerMgr.(*mgr.ContainerManager).NetworkMgr = networkMgr

// Notes(ziren): we must call containerMgr.Restore after NetworkMgr initialized,
// otherwize will panic
if err := containerMgr.Restore(ctx); err != nil {
return err
}

if err := d.addSystemLabels(); err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,15 @@ func (mgr *ContainerManager) releaseContainerResources(c *Container) error {
func (mgr *ContainerManager) releaseContainerNetwork(c *Container) error {
c.Lock()
defer c.Unlock()

// NetworkMgr is nil, which means the pouch daemon is initializing.
// And the libnetwork will also initialize, which will release all
// staled network resources(endpoint, network and namespace). So we
// don't need release the network resources.
if mgr.NetworkMgr == nil {
return nil
}

if c.NetworkSettings == nil {
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions daemon/mgr/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ func (nm *NetworkManager) EndpointCreate(ctx context.Context, endpoint *types.En
}

endpointName := containerID[:8]

// ensure the endpoint has been deleted before creating
if ep, _ := n.EndpointByName(endpointName); ep != nil {
ep.Delete(true)
}

ep, err := n.CreateEndpoint(endpointName, epOptions...)
if err != nil {
return "", err
Expand Down

0 comments on commit 8b1f8f3

Please sign in to comment.