From 50c3e56aebcdfd04530c9ec2f0f2ddc783f5f42d Mon Sep 17 00:00:00 2001 From: Ace-Tang Date: Tue, 30 Jul 2019 19:47:33 +0800 Subject: [PATCH] network: fix failed to remove network in create sandbox, if process error, should remove network without judge NetNsCreated is true, since network is created by kata and should be removed by kata, and network.Remove has judged if need to delete netns depend on NetNsCreated Fixes: #1920 Signed-off-by: Ace-Tang --- virtcontainers/api.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/virtcontainers/api.go b/virtcontainers/api.go index 8605b978f4..95d62f1de5 100644 --- a/virtcontainers/api.go +++ b/virtcontainers/api.go @@ -65,12 +65,10 @@ func CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac return s, err } -func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (*Sandbox, error) { +func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (_ *Sandbox, err error) { span, ctx := trace(ctx, "createSandboxFromConfig") defer span.Finish() - var err error - // Create the sandbox. s, err := createSandbox(ctx, sandboxConfig, factory) if err != nil { @@ -91,7 +89,7 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f // network rollback defer func() { - if err != nil && s.networkNS.NetNsCreated { + if err != nil { s.removeNetwork() } }()