diff --git a/pkg/init/cmd/service/prepare.go b/pkg/init/cmd/service/prepare.go index ca2f82632..b8c97e9bf 100644 --- a/pkg/init/cmd/service/prepare.go +++ b/pkg/init/cmd/service/prepare.go @@ -23,6 +23,7 @@ type Runtime struct { Mkdir []string `yaml:"mkdir" json:"mkdir,omitempty"` Interfaces []Interface `yaml:"interfaces" json:"interfaces,omitempty"` BindNS Namespaces `yaml:"bindNS" json:"bindNS,omitempty"` + Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"` } // Namespaces is the type for configuring paths to bind namespaces diff --git a/pkg/init/cmd/service/start.go b/pkg/init/cmd/service/start.go index d4964ba1e..0e0341846 100644 --- a/pkg/init/cmd/service/start.go +++ b/pkg/init/cmd/service/start.go @@ -11,6 +11,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" + "github.com/containerd/containerd/namespaces" specs "github.com/opencontainers/runtime-spec/specs-go" log "github.com/sirupsen/logrus" ) @@ -113,6 +114,10 @@ func start(ctx context.Context, service, sock, basePath, dumpSpec string) (strin } + if runtimeConfig.Namespace != "" { + ctx = namespaces.WithNamespace(ctx, runtimeConfig.Namespace) + } + ctr, err := client.NewContainer(ctx, service, containerd.WithSpec(spec)) if err != nil { return "", 0, "failed to create container", err