Merge pull request #948 from crosbymichael/client-tty

Add client terminal support for IO
This commit is contained in:
Phil Estes
2017-06-05 09:41:11 -04:00
committed by GitHub
21 changed files with 1040 additions and 219 deletions

View File

@@ -35,12 +35,21 @@ type execProcess struct {
stdin io.Closer
parent *initProcess
stdinPath string
stdoutPath string
stderrPath string
terminal bool
}
func newExecProcess(context context.Context, path string, r *shimapi.ExecRequest, parent *initProcess, id int) (process, error) {
e := &execProcess{
id: id,
parent: parent,
id: id,
parent: parent,
stdinPath: r.Stdin,
stdoutPath: r.Stdout,
stderrPath: r.Stderr,
terminal: r.Terminal,
}
var (
err error

View File

@@ -30,7 +30,8 @@ type initProcess struct {
// the right order when invoked in separate go routines.
// This is the case within the shim implementation as it makes use of
// the reaper interface.
mu sync.Mutex
mu sync.Mutex
id string
bundle string
console console.Console
@@ -41,6 +42,11 @@ type initProcess struct {
pid int
closers []io.Closer
stdin io.Closer
stdinPath string
stdoutPath string
stderrPath string
terminal bool
}
func newInitProcess(context context.Context, path string, r *shimapi.CreateRequest) (*initProcess, error) {
@@ -61,9 +67,13 @@ func newInitProcess(context context.Context, path string, r *shimapi.CreateReque
PdeathSignal: syscall.SIGKILL,
}
p := &initProcess{
id: r.ID,
bundle: r.Bundle,
runc: runtime,
id: r.ID,
bundle: r.Bundle,
runc: runtime,
stdinPath: r.Stdin,
stdoutPath: r.Stdout,
stderrPath: r.Stderr,
terminal: r.Terminal,
}
var (
err error

View File

@@ -192,6 +192,9 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
Pid: uint32(s.initProcess.Pid()),
Status: status,
Processes: []*task.Process{},
Stdin: s.initProcess.stdinPath,
Stdout: s.initProcess.stdoutPath,
Stderr: s.initProcess.stderrPath,
}
s.mu.Lock()
defer s.mu.Unlock()
@@ -203,10 +206,16 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
}
status = task.StatusStopped
}
o.Processes = append(o.Processes, &task.Process{
pp := &task.Process{
Pid: uint32(p.Pid()),
Status: status,
})
}
if ep, ok := p.(*execProcess); ok {
pp.Stdin = ep.stdinPath
pp.Stdout = ep.stdoutPath
pp.Stderr = ep.stderrPath
}
o.Processes = append(o.Processes, pp)
}
return o, nil
}
@@ -270,7 +279,6 @@ func (s *Service) Processes(ctx context.Context, r *shimapi.ProcessesRequest) (*
if err != nil {
return nil, err
}
ps := []*task.Process{}
for _, pid := range pids {
ps = append(ps, &task.Process{
@@ -280,9 +288,7 @@ func (s *Service) Processes(ctx context.Context, r *shimapi.ProcessesRequest) (*
resp := &shimapi.ProcessesResponse{
Processes: ps,
}
return resp, nil
}
func (s *Service) CloseStdin(ctx context.Context, r *shimapi.CloseStdinRequest) (*google_protobuf.Empty, error) {

View File

@@ -12,19 +12,6 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
)
type State struct {
pid uint32
status plugin.Status
}
func (s State) Pid() uint32 {
return s.pid
}
func (s State) Status() plugin.Status {
return s.status
}
type Task struct {
containerID string
spec []byte
@@ -56,7 +43,7 @@ func (c *Task) Start(ctx context.Context) error {
func (c *Task) State(ctx context.Context) (plugin.State, error) {
response, err := c.shim.State(ctx, &shim.StateRequest{})
if err != nil {
return nil, err
return plugin.State{}, err
}
var status plugin.Status
switch response.Status {
@@ -70,9 +57,13 @@ func (c *Task) State(ctx context.Context) (plugin.State, error) {
status = plugin.PausedStatus
// TODO: containerd.DeletedStatus
}
return &State{
pid: response.Pid,
status: status,
return plugin.State{
Pid: response.Pid,
Status: status,
Stdin: response.Stdin,
Stdout: response.Stdout,
Stderr: response.Stderr,
Terminal: response.Terminal,
}, nil
}
@@ -181,8 +172,8 @@ func (p *Process) State(ctx context.Context) (plugin.State, error) {
// use the container status for the status of the process
state, err := p.c.State(ctx)
if err != nil {
return nil, err
return state, err
}
state.(*State).pid = uint32(p.pid)
state.Pid = uint32(p.pid)
return state, nil
}