Merge pull request #2007 from AkihiroSuda/cio-fifo-path
cio: add WithFIFODir opt
This commit is contained in:
commit
e5740ca612
18
cio/io.go
18
cio/io.go
@ -6,6 +6,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/defaults"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config holds the IO configurations.
|
// Config holds the IO configurations.
|
||||||
@ -68,6 +70,7 @@ type Streams struct {
|
|||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
Stderr io.Writer
|
Stderr io.Writer
|
||||||
Terminal bool
|
Terminal bool
|
||||||
|
FIFODir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opt customize options for creating a Creator or Attach
|
// 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
|
// NewCreator returns an IO creator from the options
|
||||||
func NewCreator(opts ...Opt) Creator {
|
func NewCreator(opts ...Opt) Creator {
|
||||||
streams := &Streams{}
|
streams := &Streams{}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(streams)
|
opt(streams)
|
||||||
}
|
}
|
||||||
|
if streams.FIFODir == "" {
|
||||||
|
streams.FIFODir = defaults.DefaultFIFODir
|
||||||
|
}
|
||||||
return func(id string) (IO, error) {
|
return func(id string) (IO, error) {
|
||||||
// TODO: accept root as a param
|
fifos, err := NewFIFOSetInDir(streams.FIFODir, id, streams.Terminal)
|
||||||
root := "/run/containerd/fifo"
|
|
||||||
fifos, err := NewFIFOSetInDir(root, id, streams.Terminal)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
|
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
@ -170,6 +171,10 @@ var Command = cli.Command{
|
|||||||
Name: "detach,d",
|
Name: "detach,d",
|
||||||
Usage: "detach from the task after it has started execution",
|
Usage: "detach from the task after it has started execution",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "fifo-dir",
|
||||||
|
Usage: "directory used for storing IO FIFOs",
|
||||||
|
},
|
||||||
}, commands.SnapshotterFlags...),
|
}, commands.SnapshotterFlags...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -200,7 +205,8 @@ var Command = cli.Command{
|
|||||||
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
||||||
}
|
}
|
||||||
opts := getNewTaskOpts(context)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ var execCommand = cli.Command{
|
|||||||
Name: "exec-id",
|
Name: "exec-id",
|
||||||
Usage: "exec specific id for the process",
|
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 {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -60,10 +64,11 @@ var execCommand = cli.Command{
|
|||||||
pspec.Terminal = tty
|
pspec.Terminal = tty
|
||||||
pspec.Args = args
|
pspec.Args = args
|
||||||
|
|
||||||
ioCreator := cio.NewCreator(cio.WithStdio)
|
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
|
||||||
if tty {
|
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)
|
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2,6 +2,7 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -17,6 +18,10 @@ var startCommand = cli.Command{
|
|||||||
Name: "null-io",
|
Name: "null-io",
|
||||||
Usage: "send all IO to /dev/null",
|
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 {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -42,10 +47,11 @@ var startCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tty = spec.Process.Terminal
|
tty = spec.Process.Terminal
|
||||||
opts = getNewTaskOpts(context)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,12 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// 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) {
|
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(cio.WithStdio)
|
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
|
||||||
if checkpoint == "" {
|
if checkpoint == "" {
|
||||||
ioCreator := stdio
|
ioCreator := stdio
|
||||||
if tty {
|
if tty {
|
||||||
ioCreator = cio.NewCreator(cio.WithStdio, cio.WithTerminal)
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
|
||||||
}
|
}
|
||||||
if nullIO {
|
if nullIO {
|
||||||
if tty {
|
if tty {
|
||||||
|
@ -42,10 +42,10 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// 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) {
|
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(cio.WithStdio)
|
ioCreator := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
|
||||||
if tty {
|
if tty {
|
||||||
ioCreator = cio.NewCreator(cio.WithStdio, cio.WithTerminal)
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
|
||||||
}
|
}
|
||||||
if nullIO {
|
if nullIO {
|
||||||
if tty {
|
if tty {
|
||||||
|
@ -13,4 +13,7 @@ const (
|
|||||||
DefaultAddress = "/run/containerd/containerd.sock"
|
DefaultAddress = "/run/containerd/containerd.sock"
|
||||||
// DefaultDebugAddress is the default unix socket address for pprof data
|
// DefaultDebugAddress is the default unix socket address for pprof data
|
||||||
DefaultDebugAddress = "/run/containerd/debug.sock"
|
DefaultDebugAddress = "/run/containerd/debug.sock"
|
||||||
|
// DefaultFIFODir is the default location used by client-side cio library
|
||||||
|
// to store FIFOs.
|
||||||
|
DefaultFIFODir = "/run/containerd/fifo"
|
||||||
)
|
)
|
||||||
|
@ -21,4 +21,7 @@ const (
|
|||||||
DefaultAddress = `\\.\pipe\containerd-containerd`
|
DefaultAddress = `\\.\pipe\containerd-containerd`
|
||||||
// DefaultDebugAddress is the default winpipe address for pprof data
|
// DefaultDebugAddress is the default winpipe address for pprof data
|
||||||
DefaultDebugAddress = `\\.\pipe\containerd-debug`
|
DefaultDebugAddress = `\\.\pipe\containerd-debug`
|
||||||
|
// DefaultFIFODir is the default location used by client-side cio library
|
||||||
|
// to store FIFOs. Unused on Windows.
|
||||||
|
DefaultFIFODir = ""
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user