Merge pull request #3384 from mxpv/exec-log-uri

Support --log-uri in exec subcommand
This commit is contained in:
Michael Crosby 2019-07-02 14:34:13 -04:00 committed by GitHub
commit 876c8890ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ package tasks
import ( import (
"errors" "errors"
"net/url"
"github.com/containerd/console" "github.com/containerd/console"
"github.com/containerd/containerd/cio" "github.com/containerd/containerd/cio"
@ -53,6 +54,10 @@ var execCommand = cli.Command{
Name: "fifo-dir", Name: "fifo-dir",
Usage: "directory used for storing IO FIFOs", Usage: "directory used for storing IO FIFOs",
}, },
cli.StringFlag{
Name: "log-uri",
Usage: "log uri for custom shim logging",
},
}, },
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
var ( var (
@ -86,11 +91,31 @@ var execCommand = cli.Command{
pspec.Terminal = tty pspec.Terminal = tty
pspec.Args = args pspec.Args = args
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))} var ioCreator cio.Creator
if tty {
cioOpts = append(cioOpts, cio.WithTerminal) if logURI := context.String("log-uri"); logURI != "" {
uri, err := url.Parse(logURI)
if err != nil {
return err
}
if dir := context.String("fifo-dir"); dir != "" {
return errors.New("can't use log-uri with fifo-dir")
}
if tty {
return errors.New("can't use log-uri with tty")
}
ioCreator = cio.LogURI(uri)
} else {
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
if tty {
cioOpts = append(cioOpts, cio.WithTerminal)
}
ioCreator = cio.NewCreator(cioOpts...)
} }
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