Skip to content

Commit

Permalink
bugfix: network not found
Browse files Browse the repository at this point in the history
the network manager must be initialized after container manager has restored all containers,
as the network manager need get the real ActiveSandboxes which are returned by container manager

Signed-off-by: Eric Li <[email protected]>
  • Loading branch information
shaloulcy committed Jun 21, 2018
1 parent 196943d commit 8eae5bb
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 8eae5bb

Please sign in to comment.