Do not teardown when network namespace is removed already.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2017-08-28 05:10:17 +00:00
parent 8fd54d2f2d
commit fda30c3ad2

View File

@ -58,8 +58,10 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St
// Teardown network for sandbox. // Teardown network for sandbox.
if sandbox.NetNSPath != "" { if sandbox.NetNSPath != "" {
if _, err := os.Stat(sandbox.NetNSPath); err != nil { if _, err := os.Stat(sandbox.NetNSPath); err != nil {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to stat network namespace path %s :%v", sandbox.NetNSPath, err) return nil, fmt.Errorf("failed to stat network namespace path %s :%v", sandbox.NetNSPath, err)
} }
} else {
if teardownErr := c.netPlugin.TearDownPod(ocicni.PodNetwork{ if teardownErr := c.netPlugin.TearDownPod(ocicni.PodNetwork{
Name: sandbox.Config.GetMetadata().GetName(), Name: sandbox.Config.GetMetadata().GetName(),
Namespace: sandbox.Config.GetMetadata().GetNamespace(), Namespace: sandbox.Config.GetMetadata().GetNamespace(),
@ -69,6 +71,7 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St
}); teardownErr != nil { }); teardownErr != nil {
return nil, fmt.Errorf("failed to destroy network for sandbox %q: %v", id, teardownErr) 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. /*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. In that case, we'll not be able to remove the sandbox anymore. The chance is slim, but we should be aware of that.
In the future, once TearDownPod is idempotent, this will be fixed.*/ In the future, once TearDownPod is idempotent, this will be fixed.*/