Merge pull request #2007 from AkihiroSuda/cio-fifo-path

cio: add WithFIFODir opt
This commit is contained in:
Michael Crosby 2018-01-22 13:32:43 -05:00 committed by GitHub
commit e5740ca612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 15 deletions

View File

@ -6,6 +6,8 @@ import (
"io"
"os"
"sync"
"github.com/containerd/containerd/defaults"
)
// Config holds the IO configurations.
@ -68,6 +70,7 @@ type Streams struct {
Stdout io.Writer
Stderr io.Writer
Terminal bool
FIFODir string
}
// Opt customize options for creating a Creator or Attach
@ -92,16 +95,25 @@ func WithStreams(stdin io.Reader, stdout, stderr io.Writer) Opt {
}
}
// WithFIFODir sets the fifo directory.
// e.g. "/run/containerd/fifo", "/run/users/1001/containerd/fifo"
func WithFIFODir(dir string) Opt {
return func(opt *Streams) {
opt.FIFODir = dir
}
}
// NewCreator returns an IO creator from the options
func NewCreator(opts ...Opt) Creator {
streams := &Streams{}
for _, opt := range opts {
opt(streams)
}
if streams.FIFODir == "" {
streams.FIFODir = defaults.DefaultFIFODir
}
return func(id string) (IO, error) {
// TODO: accept root as a param
root := "/run/containerd/fifo"
fifos, err := NewFIFOSetInDir(root, id, streams.Terminal)
fifos, err := NewFIFOSetInDir(streams.FIFODir, id, streams.Terminal)
if err != nil {
return nil, err
}

View File

@ -9,6 +9,7 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
"github.com/containerd/containerd/containers"
@ -170,6 +171,10 @@ var Command = cli.Command{
Name: "detach,d",
Usage: "detach from the task after it has started execution",
},
cli.StringFlag{
Name: "fifo-dir",
Usage: "directory used for storing IO FIFOs",
},
}, commands.SnapshotterFlags...),
Action: func(context *cli.Context) error {
var (
@ -200,7 +205,8 @@ var Command = cli.Command{
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
}
opts := getNewTaskOpts(context)
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), tty, context.Bool("null-io"), opts...)
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), tty, context.Bool("null-io"), ioOpts, opts...)
if err != nil {
return err
}

View File

@ -28,6 +28,10 @@ var execCommand = cli.Command{
Name: "exec-id",
Usage: "exec specific id for the process",
},
cli.StringFlag{
Name: "fifo-dir",
Usage: "directory used for storing IO FIFOs",
},
},
Action: func(context *cli.Context) error {
var (
@ -60,10 +64,11 @@ var execCommand = cli.Command{
pspec.Terminal = tty
pspec.Args = args
ioCreator := cio.NewCreator(cio.WithStdio)
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
if tty {
ioCreator = cio.NewCreator(cio.WithStdio, cio.WithTerminal)
cioOpts = append(cioOpts, cio.WithTerminal)
}
ioCreator := cio.NewCreator(cioOpts...)
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
if err != nil {
return err

View File

@ -2,6 +2,7 @@ package tasks
import (
"github.com/containerd/console"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@ -17,6 +18,10 @@ var startCommand = cli.Command{
Name: "null-io",
Usage: "send all IO to /dev/null",
},
cli.StringFlag{
Name: "fifo-dir",
Usage: "directory used for storing IO FIFOs",
},
},
Action: func(context *cli.Context) error {
var (
@ -42,10 +47,11 @@ var startCommand = cli.Command{
}
var (
tty = spec.Process.Terminal
opts = getNewTaskOpts(context)
tty = spec.Process.Terminal
opts = getNewTaskOpts(context)
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
)
task, err := NewTask(ctx, client, container, "", tty, context.Bool("null-io"), opts...)
task, err := NewTask(ctx, client, container, "", tty, context.Bool("null-io"), ioOpts, opts...)
if err != nil {
return err
}

View File

@ -51,12 +51,12 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
}
// NewTask creates a new task
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, tty, nullIO bool, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
stdio := cio.NewCreator(cio.WithStdio)
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
if checkpoint == "" {
ioCreator := stdio
if tty {
ioCreator = cio.NewCreator(cio.WithStdio, cio.WithTerminal)
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
}
if nullIO {
if tty {

View File

@ -42,10 +42,10 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
}
// NewTask creates a new task
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
ioCreator := cio.NewCreator(cio.WithStdio)
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
ioCreator := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
if tty {
ioCreator = cio.NewCreator(cio.WithStdio, cio.WithTerminal)
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
}
if nullIO {
if tty {

View File

@ -13,4 +13,7 @@ const (
DefaultAddress = "/run/containerd/containerd.sock"
// DefaultDebugAddress is the default unix socket address for pprof data
DefaultDebugAddress = "/run/containerd/debug.sock"
// DefaultFIFODir is the default location used by client-side cio library
// to store FIFOs.
DefaultFIFODir = "/run/containerd/fifo"
)

View File

@ -21,4 +21,7 @@ const (
DefaultAddress = `\\.\pipe\containerd-containerd`
// DefaultDebugAddress is the default winpipe address for pprof data
DefaultDebugAddress = `\\.\pipe\containerd-debug`
// DefaultFIFODir is the default location used by client-side cio library
// to store FIFOs. Unused on Windows.
DefaultFIFODir = ""
)