[ctr] Add --null-io to ctr run/start

This allows all task io to be redirected to /dev/null

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-10-18 11:12:18 -04:00
parent 992280e8e2
commit 2e004086cf
4 changed files with 20 additions and 4 deletions

View File

@ -92,6 +92,10 @@ var runCommand = cli.Command{
Name: "cwd",
Usage: "specify the working directory of the process",
},
cli.BoolFlag{
Name: "null-io",
Usage: "send all IO to /dev/null",
},
}, snapshotterFlags...),
Action: func(context *cli.Context) error {
var (
@ -121,7 +125,7 @@ var runCommand = cli.Command{
if context.Bool("rm") {
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
}
task, err := newTask(ctx, client, container, context.String("checkpoint"), tty)
task, err := newTask(ctx, container, context.String("checkpoint"), tty, context.Bool("null-io"))
if err != nil {
return err
}

View File

@ -114,12 +114,15 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
return client.NewContainer(ctx, id, cOpts...)
}
func newTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, tty bool) (containerd.Task, error) {
func newTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, tty, nullIO bool) (containerd.Task, error) {
if checkpoint == "" {
io := containerd.Stdio
if tty {
io = containerd.StdioTerminal
}
if nullIO {
io = containerd.NullIO
}
return container.NewTask(ctx, io)
}
im, err := client.GetImage(ctx, checkpoint)

View File

@ -117,10 +117,13 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
)
}
func newTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty bool) (containerd.Task, error) {
func newTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool) (containerd.Task, error) {
io := containerd.Stdio
if tty {
io = containerd.StdioTerminal
}
if nullIO {
io = containerd.NullIO
}
return container.NewTask(ctx, io)
}

View File

@ -11,6 +11,12 @@ var taskStartCommand = cli.Command{
Name: "start",
Usage: "start a container that have been created",
ArgsUsage: "CONTAINER",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "null-io",
Usage: "send all IO to /dev/null",
},
},
Action: func(context *cli.Context) error {
var (
err error
@ -40,7 +46,7 @@ var taskStartCommand = cli.Command{
tty := spec.Process.Terminal
task, err := newTask(ctx, client, container, "", tty)
task, err := newTask(ctx, container, "", tty, context.Bool("null-io"))
if err != nil {
return err
}