diff --git a/pkg/server/sandbox_stop.go b/pkg/server/sandbox_stop.go index 68f11c769..a19ea1454 100644 --- a/pkg/server/sandbox_stop.go +++ b/pkg/server/sandbox_stop.go @@ -58,16 +58,19 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St // Teardown network for sandbox. if sandbox.NetNSPath != "" { if _, err := os.Stat(sandbox.NetNSPath); err != nil { - return nil, fmt.Errorf("failed to stat network namespace path %s :%v", sandbox.NetNSPath, err) - } - if teardownErr := c.netPlugin.TearDownPod(ocicni.PodNetwork{ - Name: sandbox.Config.GetMetadata().GetName(), - Namespace: sandbox.Config.GetMetadata().GetNamespace(), - ID: id, - NetNS: sandbox.NetNSPath, - PortMappings: toCNIPortMappings(sandbox.Config.GetPortMappings()), - }); teardownErr != nil { - return nil, fmt.Errorf("failed to destroy network for sandbox %q: %v", id, teardownErr) + if !os.IsNotExist(err) { + return nil, fmt.Errorf("failed to stat network namespace path %s :%v", sandbox.NetNSPath, err) + } + } else { + if teardownErr := c.netPlugin.TearDownPod(ocicni.PodNetwork{ + Name: sandbox.Config.GetMetadata().GetName(), + Namespace: sandbox.Config.GetMetadata().GetNamespace(), + ID: id, + NetNS: sandbox.NetNSPath, + PortMappings: toCNIPortMappings(sandbox.Config.GetPortMappings()), + }); teardownErr != nil { + return nil, fmt.Errorf("failed to destroy network for sandbox %q: %v", id, teardownErr) + } } /*TODO:It is still possible that cri-containerd crashes after we teardown the network, but before we remove the network namespace. In that case, we'll not be able to remove the sandbox anymore. The chance is slim, but we should be aware of that.