Add container Exec support.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2017-08-07 18:59:10 +00:00
parent 8b56c91ec5
commit 54286313ce
6 changed files with 127 additions and 12 deletions

View File

@@ -43,10 +43,9 @@ func (c *criContainerdService) ExecSync(ctx context.Context, r *runtime.ExecSync
}
}()
var stdin, stdout, stderr bytes.Buffer
var stdout, stderr bytes.Buffer
exitCode, err := c.execInContainer(ctx, r.GetContainerId(), execOptions{
cmd: r.GetCmd(),
stdin: &stdin,
stdout: &stdout,
stderr: &stderr,
timeout: time.Duration(r.GetTimeout()) * time.Second,
@@ -106,6 +105,10 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o
pspec.Args = opts.cmd
pspec.Terminal = opts.tty
if opts.stdin == nil {
// Create empty buffer if stdin is nil.
opts.stdin = new(bytes.Buffer)
}
execID := generateID()
process, err := task.Exec(ctx, execID, pspec, containerd.NewIOWithTerminal(
opts.stdin,