From 50a63b2a576bd72eee91fa46cc3d8b33a428c0e0 Mon Sep 17 00:00:00 2001 From: Eric Li Date: Tue, 5 Jun 2018 22:41:47 +0800 Subject: [PATCH] bugfix: network not found 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 --- daemon/daemon.go | 14 ++++++++------ daemon/mgr/container.go | 8 ++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 36ad2d4b9c..cfd7ba0f2a 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -6,6 +6,7 @@ import ( "path" "plugin" "reflect" + "time" "github.com/alibaba/pouch/apis/plugins" "github.com/alibaba/pouch/apis/server" @@ -169,6 +170,13 @@ 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 @@ -176,12 +184,6 @@ func (d *Daemon) Run() error { 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 } diff --git a/daemon/mgr/container.go b/daemon/mgr/container.go index 5dc8b82e72..97b5449672 100644 --- a/daemon/mgr/container.go +++ b/daemon/mgr/container.go @@ -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