From ac98ef7439c3ea6087caf3c6f07b1d9de08366ea Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 15 May 2017 13:41:57 -0700 Subject: [PATCH] Add --net-host for testing host networking Add `--net-host` to `ctr run` to test containers running in host networking. Signed-off-by: Michael Crosby --- cmd/ctr/run.go | 4 ++++ cmd/ctr/run_unix.go | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/ctr/run.go b/cmd/ctr/run.go index 14fcdf92b..fe9a25aa4 100644 --- a/cmd/ctr/run.go +++ b/cmd/ctr/run.go @@ -51,6 +51,10 @@ var runCommand = cli.Command{ Name: "readonly", Usage: "set the containers filesystem as readonly", }, + cli.BoolFlag{ + Name: "net-host", + Usage: "enable host networking for the container", + }, }, Action: func(context *cli.Context) error { var ( diff --git a/cmd/ctr/run_unix.go b/cmd/ctr/run_unix.go index 64d765d0c..d67f77943 100644 --- a/cmd/ctr/run_unix.go +++ b/cmd/ctr/run_unix.go @@ -92,7 +92,7 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) (*specs. if cwd == "" { cwd = "/" } - return &specs.Spec{ + s := &specs.Spec{ Version: specs.Version, Platform: specs.Platform{ OS: runtime.GOOS, @@ -211,12 +211,15 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) (*specs. { Type: "mount", }, - { - Type: "network", - }, }, }, - }, nil + } + if !context.Bool("net-host") { + s.Linux.Namespaces = append(s.Linux.Namespaces, specs.LinuxNamespace{ + Type: "network", + }) + } + return s, nil } func customSpec(configPath string, rootfs string) (*specs.Spec, error) {