Skip to content

Commit

Permalink
bugfix: skip teardown network, if the sandbox has been stopped
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
  • Loading branch information
YaoZengzeng committed Jun 19, 2018
1 parent 94ac747 commit 08ea68f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
24 changes: 15 additions & 9 deletions cri/v1alpha1/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,21 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb

// Teardown network of the pod, if it is not in host network mode.
if !hostNet {
err = c.CniMgr.TearDownPodNetwork(&ocicni.PodNetwork{
Name: metadata.GetName(),
Namespace: metadata.GetNamespace(),
ID: podSandboxID,
NetNS: sandboxMeta.NetNSPath,
PortMappings: toCNIPortMappings(sandboxMeta.Config.GetPortMappings()),
})
if err != nil {
return nil, err
_, err = os.Stat(sandboxMeta.NetNSPath)
// If the sandbox has been stopped, the corresponding network namespace will not exist.
if err == nil {
err = c.CniMgr.TearDownPodNetwork(&ocicni.PodNetwork{
Name: metadata.GetName(),
Namespace: metadata.GetNamespace(),
ID: podSandboxID,
NetNS: sandboxMeta.NetNSPath,
PortMappings: toCNIPortMappings(sandboxMeta.Config.GetPortMappings()),
})
if err != nil {
return nil, err
}
} else if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to stat network namespace file %s of sandbox %s: %v", sandboxMeta.NetNSPath, podSandboxID, err)
}
}

Expand Down
24 changes: 15 additions & 9 deletions cri/v1alpha2/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,21 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb

// Teardown network of the pod, if it is not in host network mode.
if !hostNet {
err = c.CniMgr.TearDownPodNetwork(&ocicni.PodNetwork{
Name: metadata.GetName(),
Namespace: metadata.GetNamespace(),
ID: podSandboxID,
NetNS: sandboxMeta.NetNSPath,
PortMappings: toCNIPortMappings(sandboxMeta.Config.GetPortMappings()),
})
if err != nil {
return nil, err
_, err = os.Stat(sandboxMeta.NetNSPath)
// If the sandbox has been stopped, the corresponding network namespace will not exist.
if err == nil {
err = c.CniMgr.TearDownPodNetwork(&ocicni.PodNetwork{
Name: metadata.GetName(),
Namespace: metadata.GetNamespace(),
ID: podSandboxID,
NetNS: sandboxMeta.NetNSPath,
PortMappings: toCNIPortMappings(sandboxMeta.Config.GetPortMappings()),
})
if err != nil {
return nil, err
}
} else if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to stat network namespace file %s of sandbox %s: %v", sandboxMeta.NetNSPath, podSandboxID, err)
}
}

Expand Down

0 comments on commit 08ea68f

Please sign in to comment.