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

fix: return error if it fails to tear down network in stopsandbox #2836

Merged
merged 2 commits into from
May 13, 2019
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
3 changes: 2 additions & 1 deletion cri/ocicni/cni_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ func (c *CniManager) TearDownPodNetwork(podNetwork *ocicni.PodNetwork) error {
return nil
}

// if netNSPath is not found, should return the error of IsNotExist.
// if netNSPath is not found, dont return error.
if _, err = os.Stat(podNetwork.NetNS); err != nil {
if os.IsNotExist(err) {
logrus.Warnf("failed to find network namespace file %s of sandbox %s", podNetwork.NetNS, podNetwork.ID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not output the detailed error?

return nil
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cri/v1alpha2/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
// Teardown network of the pod, if it is not in host network mode.
if sandboxNetworkMode(sandboxMeta.Config) != runtime.NamespaceMode_NODE {
if err = c.teardownNetwork(podSandboxID, sandboxMeta.NetNS, sandboxMeta.Config); err != nil {
logrus.Warnf("failed to find network namespace file %s of sandbox %s which may have been already stopped", sandboxMeta.NetNS, podSandboxID)
return nil, fmt.Errorf("failed to teardown network of sandbox %s, ns path: %v", podSandboxID, sandboxMeta.NetNS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not output the detailed err?

}
}

Expand Down
10 changes: 5 additions & 5 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,6 @@ func (mgr *ContainerManager) prepareContainerNetwork(ctx context.Context, c *Con
return nil
}

// network is prepared by upper system. do nothing here.
if IsNetNS(networkMode) {
return nil
}

// initialise host network mode
if IsHost(networkMode) {
hostname, err := os.Hostname()
Expand All @@ -703,6 +698,11 @@ func (mgr *ContainerManager) prepareContainerNetwork(ctx context.Context, c *Con
return err
}

// network is prepared by upper system. do nothing here.
if IsNetNS(networkMode) {
return nil
}

// initialise network endpoint
if c.NetworkSettings == nil {
return nil
Expand Down