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 7, 2018
1 parent 74e5ac7 commit 50a63b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 8 additions & 6 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"
"plugin"
"reflect"
"time"

"github.com/alibaba/pouch/apis/plugins"
"github.com/alibaba/pouch/apis/server"
Expand Down Expand Up @@ -169,19 +170,20 @@ func (d *Daemon) Run() error {
}
d.containerMgr = containerMgr

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

// ensure all container has been restored
time.Sleep(100 * time.Millisecond)

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
8 changes: 8 additions & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,14 @@ func (mgr *ContainerManager) markStoppedAndRelease(c *Container, m *ctrd.Message
mgr.IOs.Remove(c.ID)
}

// 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
}

// No network binded, just return
if c.NetworkSettings == nil {
return nil
Expand Down

0 comments on commit 50a63b2

Please sign in to comment.