Skip to content

Commit

Permalink
shimv2: remove use containerd ns as netns
Browse files Browse the repository at this point in the history
```
//the network namespace created by cni plugin
netns, err = namespaces.NamespaceRequired(ctx)
if err != nil {
        return nil, errors.Wrap(err, "create namespace")
}
```

the netns is a containerd namespace concept, it not netns, event a cni
set netns for this, this is a tricky way, so remove the logic.

Fixes: kata-containers#1692

Signed-off-by: Ace-Tang <[email protected]>
  • Loading branch information
Ace-Tang committed May 22, 2019
1 parent e2d894d commit d6b3bff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
28 changes: 6 additions & 22 deletions containerd-shim-v2/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ package containerdshim
import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/containerd/typeurl"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/pkg/errors"
"os"
"path/filepath"

taskAPI "github.com/containerd/containerd/runtime/v2/task"

Expand All @@ -30,7 +31,7 @@ import (
crioption "github.com/containerd/cri-containerd/pkg/api/runtimeoptions/v1"
)

func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns string) (*container, error) {
func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*container, error) {
rootFs := vc.RootFs{Mounted: s.mount}
if len(r.Rootfs) == 1 {
m := r.Rootfs[0]
Expand All @@ -40,7 +41,7 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns
}

detach := !r.Terminal
ociSpec, bundlePath, err := loadSpec(r, netns)
ociSpec, bundlePath, err := loadSpec(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -124,7 +125,7 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns
return container, nil
}

func loadSpec(r *taskAPI.CreateTaskRequest, netns string) (*oci.CompatOCISpec, string, error) {
func loadSpec(r *taskAPI.CreateTaskRequest) (*oci.CompatOCISpec, string, error) {
// Checks the MUST and MUST NOT from OCI runtime specification
bundlePath, err := validBundle(r.ID, r.Bundle)
if err != nil {
Expand All @@ -136,23 +137,6 @@ func loadSpec(r *taskAPI.CreateTaskRequest, netns string) (*oci.CompatOCISpec, s
return nil, "", err
}

//set the network namespace path
//this set will be applied to sandbox's
//network config and has nothing to
//do with containers in the sandbox since
//networkNamespace has been ignored by
//kata-agent in sandbox.

for _, n := range ociSpec.Linux.Namespaces {
if n.Type != specs.NetworkNamespace {
continue
}

if n.Path == "" {
n.Path = netns
}
}

// Todo:
// Since there is a bug in kata for sharedPidNs, here to
// remove the pidns to disable the sharePidNs temporarily,
Expand Down
9 changes: 1 addition & 8 deletions containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,8 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
defer s.mu.Unlock()

var c *container
var netns string

//the network namespace created by cni plugin
netns, err = namespaces.NamespaceRequired(ctx)
if err != nil {
return nil, errors.Wrap(err, "create namespace")
}

c, err = create(ctx, s, r, netns)
c, err = create(ctx, s, r)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d6b3bff

Please sign in to comment.