NewTask avoid unnecessary cio.NewCreator calls

Signed-off-by: Guanjun Gong <gongguanjun@hotmail.com>
This commit is contained in:
Guanjun Gong 2020-09-10 15:12:44 +08:00 committed by gongguan
parent d43d546a8d
commit 0dea724fc0

View File

@ -72,7 +72,6 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
stdinC := &stdinCloser{
stdin: os.Stdin,
}
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
if checkpoint != "" {
im, err := client.GetImage(ctx, checkpoint)
if err != nil {
@ -80,22 +79,22 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
}
opts = append(opts, containerd.WithTaskCheckpoint(im))
}
ioCreator := stdio
var ioCreator cio.Creator
if con != nil {
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
}
if nullIO {
if con != nil {
if nullIO {
return nil, errors.New("tty and null-io cannot be used together")
}
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
} else if nullIO {
ioCreator = cio.NullIO
}
if logURI != "" {
} else if logURI != "" {
u, err := url.Parse(logURI)
if err != nil {
return nil, err
}
ioCreator = cio.LogURI(u)
} else {
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
}
t, err := container.NewTask(ctx, ioCreator, opts...)
if err != nil {