From 4c48ad780ffafc6b8309d8466ae625fb9ff5a937 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Thu, 29 Jun 2017 01:27:49 +0000 Subject: [PATCH] Do not teardown network namespace when using host network. Signed-off-by: Lantao Liu --- pkg/server/sandbox_stop.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/server/sandbox_stop.go b/pkg/server/sandbox_stop.go index 9973b85db..dc56f0f7c 100644 --- a/pkg/server/sandbox_stop.go +++ b/pkg/server/sandbox_stop.go @@ -68,9 +68,11 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St // Teardown network for sandbox. _, err = c.os.Stat(sandbox.NetNS) if err == nil { - if teardownErr := c.netPlugin.TearDownPod(sandbox.NetNS, sandbox.Config.GetMetadata().GetNamespace(), - sandbox.Config.GetMetadata().GetName(), id); teardownErr != nil { - return nil, fmt.Errorf("failed to destroy network for sandbox %q: %v", id, teardownErr) + if !sandbox.Config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostNetwork() { + if teardownErr := c.netPlugin.TearDownPod(sandbox.NetNS, sandbox.Config.GetMetadata().GetNamespace(), + sandbox.Config.GetMetadata().GetName(), id); teardownErr != nil { + return nil, fmt.Errorf("failed to destroy network for sandbox %q: %v", id, teardownErr) + } } } else if !os.IsNotExist(err) { // It's ok for sandbox.NetNS to *not* exist return nil, fmt.Errorf("failed to stat netns path for sandbox %q before tearing down the network: %v", id, err)