From 4b9ffadb2ed888f87c9dc692d9003abbe2cdeca1 Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Wed, 17 Jan 2018 14:32:51 +0000 Subject: [PATCH] Add support for runtime containerd namespace configuration Signed-off-by: Justin Cormack --- pkg/init/cmd/service/prepare.go | 1 + pkg/init/cmd/service/start.go | 5 +++++ 2 files changed, 6 insertions(+) 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