@@ -17,7 +17,6 @@ limitations under the License.
1717package server
1818
1919import (
20- "os"
2120 "time"
2221
2322 "github.com/containerd/containerd"
@@ -60,23 +59,21 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
6059 }
6160
6261 // Teardown network for sandbox.
63- if sandbox .NetNSPath != "" && sandbox .NetNS != nil {
64- if _ , err := os .Stat (sandbox .NetNSPath ); err != nil {
65- if ! os .IsNotExist (err ) {
66- return nil , errors .Wrapf (err , "failed to stat network namespace path %s" , sandbox .NetNSPath )
67- }
68- } else {
69- if teardownErr := c .teardownPod (id , sandbox .NetNSPath , sandbox .Config ); teardownErr != nil {
70- return nil , errors .Wrapf (teardownErr , "failed to destroy network for sandbox %q" , id )
71- }
62+ if sandbox .NetNSPath != "" {
63+ netNSPath := sandbox .NetNSPath
64+ if sandbox .NetNS == nil || sandbox .NetNS .Closed () {
65+ // Use empty netns path if netns is not available. This is defined in:
66+ // https://github.com/containernetworking/cni/blob/v0.7.0-alpha1/SPEC.md
67+ netNSPath = ""
7268 }
73- /*TODO:It is still possible that containerd crashes after we teardown the network, but before we remove the network namespace.
74- In that case, we'll not be able to remove the sandbox anymore. The chance is slim, but we should be aware of that.
75- In the future, once TearDownPod is idempotent, this will be fixed.*/
76-
77- //Close the sandbox network namespace if it was created
78- if err = sandbox .NetNS .Remove (); err != nil {
79- return nil , errors .Wrapf (err , "failed to remove network namespace for sandbox %q" , id )
69+ if err := c .teardownPod (id , netNSPath , sandbox .Config ); err != nil {
70+ return nil , errors .Wrapf (err , "failed to destroy network for sandbox %q" , id )
71+ }
72+ // Close the sandbox network namespace if it was created
73+ if sandbox .NetNS != nil {
74+ if err = sandbox .NetNS .Remove (); err != nil {
75+ return nil , errors .Wrapf (err , "failed to remove network namespace for sandbox %q" , id )
76+ }
8077 }
8178 }
8279
0 commit comments