Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
containerd-shim-kata: Create the NetworkNs if it hasn't been create
Browse files Browse the repository at this point in the history
If the networkNs hasn't been created, created it here.

Fixes: kata-containers#485

Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Sep 17, 2018
1 parent 25415f7 commit 179a0db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion containerd-shim/kata/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
vf "github.com/kata-containers/runtime/virtcontainers/factory"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"

"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -208,6 +208,11 @@ func createSandbox(ctx context.Context, ociSpec oci.CompatOCISpec, runtimeConfig

sandboxConfig.Stateful = true

//setup the networkNamespace if it hasn't been created, such as the using the CNM
if err = setupNetworkNamespace(&sandboxConfig.NetworkConfig); err != nil {
return nil, err
}

sandbox, err := vci.CreateSandbox(ctx, sandboxConfig)
if err != nil {
return nil, err
Expand Down
27 changes: 27 additions & 0 deletions containerd-shim/kata/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2018 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//

package kata

import (
"github.com/containernetworking/plugins/pkg/ns"
vc "github.com/kata-containers/runtime/virtcontainers"
)

func setupNetworkNamespace(config *vc.NetworkConfig) error {
if config.NetNSPath != "" {
return nil
}

n, err := ns.NewNS()
if err != nil {
return err
}

config.NetNSPath = n.Path()
config.NetNsCreated = true

return nil
}

0 comments on commit 179a0db

Please sign in to comment.