Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: network not found #1473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If change this, won't panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the NetworkManange is nil, markStoppedAndRelease will return directly. So it won't 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