Add exec APIs
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
cccf5d3723
commit
7715ddcefa
19 changed files with 759 additions and 126 deletions
|
@ -1,6 +1,7 @@
|
|||
package execution
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
|
@ -203,6 +204,33 @@ func (s *Service) Events(r *api.EventsRequest, server api.ContainerService_Event
|
|||
return s.collector.forward(w)
|
||||
}
|
||||
|
||||
func (s *Service) Exec(ctx context.Context, r *api.ExecRequest) (*api.ExecResponse, error) {
|
||||
c, err := s.getContainer(r.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l, ok := c.(containerd.LinuxContainer)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot exec into a non linux container")
|
||||
}
|
||||
process, err := l.Exec(ctx, containerd.ExecOpts{
|
||||
Spec: r.Spec.Value,
|
||||
IO: containerd.IO{
|
||||
Stdin: r.Stdin,
|
||||
Stdout: r.Stdout,
|
||||
Stderr: r.Stderr,
|
||||
Terminal: r.Terminal,
|
||||
},
|
||||
})
|
||||
state, err := process.State(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &api.ExecResponse{
|
||||
Pid: state.Pid(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) getContainer(id string) (containerd.Container, error) {
|
||||
s.mu.Lock()
|
||||
c, ok := s.containers[id]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue