Skip to content

Commit 8eae5bb

Browse files
committed
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 <[email protected]>
1 parent 196943d commit 8eae5bb

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

daemon/daemon.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,17 @@ func (d *Daemon) Run() error {
169169
}
170170
d.containerMgr = containerMgr
171171

172+
if err := containerMgr.Restore(ctx); err != nil {
173+
return err
174+
}
175+
172176
networkMgr, err := internal.GenNetworkMgr(d.config, d)
173177
if err != nil {
174178
return err
175179
}
176180
d.networkMgr = networkMgr
177181
containerMgr.(*mgr.ContainerManager).NetworkMgr = networkMgr
178182

179-
// Notes(ziren): we must call containerMgr.Restore after NetworkMgr initialized,
180-
// otherwize will panic
181-
if err := containerMgr.Restore(ctx); err != nil {
182-
return err
183-
}
184-
185183
if err := d.addSystemLabels(); err != nil {
186184
return err
187185
}

daemon/mgr/container.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,15 @@ func (mgr *ContainerManager) releaseContainerResources(c *Container) error {
19391939
func (mgr *ContainerManager) releaseContainerNetwork(c *Container) error {
19401940
c.Lock()
19411941
defer c.Unlock()
1942+
1943+
// NetworkMgr is nil, which means the pouch daemon is initializing.
1944+
// And the libnetwork will also initialize, which will release all
1945+
// staled network resources(endpoint, network and namespace). So we
1946+
// don't need release the network resources.
1947+
if mgr.NetworkMgr == nil {
1948+
return nil
1949+
}
1950+
19421951
if c.NetworkSettings == nil {
19431952
return nil
19441953
}

daemon/mgr/network.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ func (nm *NetworkManager) EndpointCreate(ctx context.Context, endpoint *types.En
284284
}
285285

286286
endpointName := containerID[:8]
287+
288+
// ensure the endpoint has been deleted before creating
289+
if ep, _ := n.EndpointByName(endpointName); ep != nil {
290+
ep.Delete(true)
291+
}
292+
287293
ep, err := n.CreateEndpoint(endpointName, epOptions...)
288294
if err != nil {
289295
return "", err

0 commit comments

Comments
 (0)