Start work on Container and Process model

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-12-02 15:37:16 -08:00
parent 6641888667
commit 32bf0f69fd
38 changed files with 525 additions and 353 deletions

View file

@ -55,10 +55,11 @@ func (x Status) String() string {
func (Status) EnumDescriptor() ([]byte, []int) { return fileDescriptorContainer, []int{0} } func (Status) EnumDescriptor() ([]byte, []int) { return fileDescriptorContainer, []int{0} }
type CreateProcessRequest struct { type CreateProcessRequest struct {
Process *Process `protobuf:"bytes,1,opt,name=process" json:"process,omitempty"` ContainerId string `protobuf:"bytes,1,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"`
Stdin string `protobuf:"bytes,2,opt,name=stdin,proto3" json:"stdin,omitempty"` Process *Process `protobuf:"bytes,2,opt,name=process" json:"process,omitempty"`
Stdout string `protobuf:"bytes,3,opt,name=stdout,proto3" json:"stdout,omitempty"` Stdin string `protobuf:"bytes,3,opt,name=stdin,proto3" json:"stdin,omitempty"`
Stderr string `protobuf:"bytes,4,opt,name=stderr,proto3" json:"stderr,omitempty"` Stdout string `protobuf:"bytes,4,opt,name=stdout,proto3" json:"stdout,omitempty"`
Stderr string `protobuf:"bytes,5,opt,name=stderr,proto3" json:"stderr,omitempty"`
} }
func (m *CreateProcessRequest) Reset() { *m = CreateProcessRequest{} } func (m *CreateProcessRequest) Reset() { *m = CreateProcessRequest{} }
@ -85,13 +86,15 @@ func (*Container) ProtoMessage() {}
func (*Container) Descriptor() ([]byte, []int) { return fileDescriptorContainer, []int{2} } func (*Container) Descriptor() ([]byte, []int) { return fileDescriptorContainer, []int{2} }
type Process struct { type Process struct {
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Pid uint64 `protobuf:"varint,2,opt,name=pid,proto3" json:"pid,omitempty"` Pid uint64 `protobuf:"varint,2,opt,name=pid,proto3" json:"pid,omitempty"`
Args []string `protobuf:"bytes,3,rep,name=args" json:"args,omitempty"` Args []string `protobuf:"bytes,3,rep,name=args" json:"args,omitempty"`
Env []string `protobuf:"bytes,4,rep,name=env" json:"env,omitempty"` Env []string `protobuf:"bytes,4,rep,name=env" json:"env,omitempty"`
User *User `protobuf:"bytes,5,opt,name=user" json:"user,omitempty"` User *User `protobuf:"bytes,5,opt,name=user" json:"user,omitempty"`
Cwd string `protobuf:"bytes,6,opt,name=cwd,proto3" json:"cwd,omitempty"` Cwd string `protobuf:"bytes,6,opt,name=cwd,proto3" json:"cwd,omitempty"`
Terminal bool `protobuf:"varint,7,opt,name=terminal,proto3" json:"terminal,omitempty"` Terminal bool `protobuf:"varint,7,opt,name=terminal,proto3" json:"terminal,omitempty"`
Status Status `protobuf:"varint,8,opt,name=status,proto3,enum=containerd.v1.Status" json:"status,omitempty"`
ExitStatus uint32 `protobuf:"varint,9,opt,name=exit_status,json=exitStatus,proto3" json:"exit_status,omitempty"`
} }
func (m *Process) Reset() { *m = Process{} } func (m *Process) Reset() { *m = Process{} }
@ -240,8 +243,9 @@ func (this *CreateProcessRequest) GoString() string {
if this == nil { if this == nil {
return "nil" return "nil"
} }
s := make([]string, 0, 8) s := make([]string, 0, 9)
s = append(s, "&execution.CreateProcessRequest{") s = append(s, "&execution.CreateProcessRequest{")
s = append(s, "ContainerId: "+fmt.Sprintf("%#v", this.ContainerId)+",\n")
if this.Process != nil { if this.Process != nil {
s = append(s, "Process: "+fmt.Sprintf("%#v", this.Process)+",\n") s = append(s, "Process: "+fmt.Sprintf("%#v", this.Process)+",\n")
} }
@ -282,7 +286,7 @@ func (this *Process) GoString() string {
if this == nil { if this == nil {
return "nil" return "nil"
} }
s := make([]string, 0, 11) s := make([]string, 0, 13)
s = append(s, "&execution.Process{") s = append(s, "&execution.Process{")
s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n") s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n")
s = append(s, "Pid: "+fmt.Sprintf("%#v", this.Pid)+",\n") s = append(s, "Pid: "+fmt.Sprintf("%#v", this.Pid)+",\n")
@ -293,6 +297,8 @@ func (this *Process) GoString() string {
} }
s = append(s, "Cwd: "+fmt.Sprintf("%#v", this.Cwd)+",\n") s = append(s, "Cwd: "+fmt.Sprintf("%#v", this.Cwd)+",\n")
s = append(s, "Terminal: "+fmt.Sprintf("%#v", this.Terminal)+",\n") s = append(s, "Terminal: "+fmt.Sprintf("%#v", this.Terminal)+",\n")
s = append(s, "Status: "+fmt.Sprintf("%#v", this.Status)+",\n")
s = append(s, "ExitStatus: "+fmt.Sprintf("%#v", this.ExitStatus)+",\n")
s = append(s, "}") s = append(s, "}")
return strings.Join(s, "") return strings.Join(s, "")
} }
@ -872,9 +878,15 @@ func (m *CreateProcessRequest) MarshalTo(dAtA []byte) (int, error) {
_ = i _ = i
var l int var l int
_ = l _ = l
if m.Process != nil { if len(m.ContainerId) > 0 {
dAtA[i] = 0xa dAtA[i] = 0xa
i++ i++
i = encodeVarintContainer(dAtA, i, uint64(len(m.ContainerId)))
i += copy(dAtA[i:], m.ContainerId)
}
if m.Process != nil {
dAtA[i] = 0x12
i++
i = encodeVarintContainer(dAtA, i, uint64(m.Process.Size())) i = encodeVarintContainer(dAtA, i, uint64(m.Process.Size()))
n1, err := m.Process.MarshalTo(dAtA[i:]) n1, err := m.Process.MarshalTo(dAtA[i:])
if err != nil { if err != nil {
@ -883,19 +895,19 @@ func (m *CreateProcessRequest) MarshalTo(dAtA []byte) (int, error) {
i += n1 i += n1
} }
if len(m.Stdin) > 0 { if len(m.Stdin) > 0 {
dAtA[i] = 0x12 dAtA[i] = 0x1a
i++ i++
i = encodeVarintContainer(dAtA, i, uint64(len(m.Stdin))) i = encodeVarintContainer(dAtA, i, uint64(len(m.Stdin)))
i += copy(dAtA[i:], m.Stdin) i += copy(dAtA[i:], m.Stdin)
} }
if len(m.Stdout) > 0 { if len(m.Stdout) > 0 {
dAtA[i] = 0x1a dAtA[i] = 0x22
i++ i++
i = encodeVarintContainer(dAtA, i, uint64(len(m.Stdout))) i = encodeVarintContainer(dAtA, i, uint64(len(m.Stdout)))
i += copy(dAtA[i:], m.Stdout) i += copy(dAtA[i:], m.Stdout)
} }
if len(m.Stderr) > 0 { if len(m.Stderr) > 0 {
dAtA[i] = 0x22 dAtA[i] = 0x2a
i++ i++
i = encodeVarintContainer(dAtA, i, uint64(len(m.Stderr))) i = encodeVarintContainer(dAtA, i, uint64(len(m.Stderr)))
i += copy(dAtA[i:], m.Stderr) i += copy(dAtA[i:], m.Stderr)
@ -1058,6 +1070,16 @@ func (m *Process) MarshalTo(dAtA []byte) (int, error) {
} }
i++ i++
} }
if m.Status != 0 {
dAtA[i] = 0x40
i++
i = encodeVarintContainer(dAtA, i, uint64(m.Status))
}
if m.ExitStatus != 0 {
dAtA[i] = 0x48
i++
i = encodeVarintContainer(dAtA, i, uint64(m.ExitStatus))
}
return i, nil return i, nil
} }
@ -1507,6 +1529,10 @@ func encodeVarintContainer(dAtA []byte, offset int, v uint64) int {
func (m *CreateProcessRequest) Size() (n int) { func (m *CreateProcessRequest) Size() (n int) {
var l int var l int
_ = l _ = l
l = len(m.ContainerId)
if l > 0 {
n += 1 + l + sovContainer(uint64(l))
}
if m.Process != nil { if m.Process != nil {
l = m.Process.Size() l = m.Process.Size()
n += 1 + l + sovContainer(uint64(l)) n += 1 + l + sovContainer(uint64(l))
@ -1590,6 +1616,12 @@ func (m *Process) Size() (n int) {
if m.Terminal { if m.Terminal {
n += 2 n += 2
} }
if m.Status != 0 {
n += 1 + sovContainer(uint64(m.Status))
}
if m.ExitStatus != 0 {
n += 1 + sovContainer(uint64(m.ExitStatus))
}
return n return n
} }
@ -1773,6 +1805,7 @@ func (this *CreateProcessRequest) String() string {
return "nil" return "nil"
} }
s := strings.Join([]string{`&CreateProcessRequest{`, s := strings.Join([]string{`&CreateProcessRequest{`,
`ContainerId:` + fmt.Sprintf("%v", this.ContainerId) + `,`,
`Process:` + strings.Replace(fmt.Sprintf("%v", this.Process), "Process", "Process", 1) + `,`, `Process:` + strings.Replace(fmt.Sprintf("%v", this.Process), "Process", "Process", 1) + `,`,
`Stdin:` + fmt.Sprintf("%v", this.Stdin) + `,`, `Stdin:` + fmt.Sprintf("%v", this.Stdin) + `,`,
`Stdout:` + fmt.Sprintf("%v", this.Stdout) + `,`, `Stdout:` + fmt.Sprintf("%v", this.Stdout) + `,`,
@ -1816,6 +1849,8 @@ func (this *Process) String() string {
`User:` + strings.Replace(fmt.Sprintf("%v", this.User), "User", "User", 1) + `,`, `User:` + strings.Replace(fmt.Sprintf("%v", this.User), "User", "User", 1) + `,`,
`Cwd:` + fmt.Sprintf("%v", this.Cwd) + `,`, `Cwd:` + fmt.Sprintf("%v", this.Cwd) + `,`,
`Terminal:` + fmt.Sprintf("%v", this.Terminal) + `,`, `Terminal:` + fmt.Sprintf("%v", this.Terminal) + `,`,
`Status:` + fmt.Sprintf("%v", this.Status) + `,`,
`ExitStatus:` + fmt.Sprintf("%v", this.ExitStatus) + `,`,
`}`, `}`,
}, "") }, "")
return s return s
@ -2003,6 +2038,35 @@ func (m *CreateProcessRequest) Unmarshal(dAtA []byte) error {
} }
switch fieldNum { switch fieldNum {
case 1: case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ContainerId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowContainer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthContainer
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ContainerId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Process", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Process", wireType)
} }
@ -2035,7 +2099,7 @@ func (m *CreateProcessRequest) Unmarshal(dAtA []byte) error {
return err return err
} }
iNdEx = postIndex iNdEx = postIndex
case 2: case 3:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Stdin", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Stdin", wireType)
} }
@ -2064,7 +2128,7 @@ func (m *CreateProcessRequest) Unmarshal(dAtA []byte) error {
} }
m.Stdin = string(dAtA[iNdEx:postIndex]) m.Stdin = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex iNdEx = postIndex
case 3: case 4:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Stdout", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Stdout", wireType)
} }
@ -2093,7 +2157,7 @@ func (m *CreateProcessRequest) Unmarshal(dAtA []byte) error {
} }
m.Stdout = string(dAtA[iNdEx:postIndex]) m.Stdout = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex iNdEx = postIndex
case 4: case 5:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Stderr", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Stderr", wireType)
} }
@ -2603,6 +2667,44 @@ func (m *Process) Unmarshal(dAtA []byte) error {
} }
} }
m.Terminal = bool(v != 0) m.Terminal = bool(v != 0)
case 8:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType)
}
m.Status = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowContainer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Status |= (Status(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 9:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field ExitStatus", wireType)
}
m.ExitStatus = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowContainer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.ExitStatus |= (uint32(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipContainer(dAtA[iNdEx:]) skippy, err := skipContainer(dAtA[iNdEx:])
@ -4024,56 +4126,59 @@ var (
func init() { proto.RegisterFile("container.proto", fileDescriptorContainer) } func init() { proto.RegisterFile("container.proto", fileDescriptorContainer) }
var fileDescriptorContainer = []byte{ var fileDescriptorContainer = []byte{
// 812 bytes of a gzipped FileDescriptorProto // 855 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x56, 0x51, 0x73, 0xd2, 0x4a, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x56, 0xd1, 0x72, 0xf2, 0x44,
0x14, 0x6e, 0x80, 0x86, 0x72, 0xb8, 0xf4, 0x72, 0xb7, 0xc0, 0x64, 0x98, 0x7b, 0x29, 0x37, 0x56, 0x14, 0x6e, 0x80, 0x86, 0xe6, 0xf0, 0xe7, 0x17, 0xb7, 0x81, 0xc9, 0x30, 0xca, 0xcf, 0x1f, 0xab,
0x65, 0x9c, 0x29, 0xad, 0xd5, 0xf1, 0xc5, 0xa7, 0x16, 0x10, 0xe9, 0x28, 0xe2, 0x52, 0xc6, 0x19, 0x32, 0xce, 0x94, 0x56, 0x74, 0xbc, 0xf1, 0xaa, 0x05, 0x44, 0x3a, 0x8a, 0xb8, 0x94, 0x71, 0xc6,
0x5f, 0x6a, 0x4a, 0x76, 0x68, 0x1c, 0x9a, 0xd0, 0x64, 0x53, 0xc7, 0x37, 0x7f, 0x81, 0xff, 0xc2, 0x1b, 0x4c, 0xc9, 0x0e, 0x8d, 0x43, 0x13, 0x9a, 0x6c, 0xaa, 0xde, 0xf5, 0x65, 0x7c, 0x80, 0xbe,
0x77, 0xfd, 0x17, 0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00, 0x1c, 0x1d, 0xbb, 0x9f, 0x44, 0x9b, 0x9e, 0x7f, 0xf0, 0xf8, 0x54, 0xde, 0xfb, 0xfb, 0xa9, 0xbc,
0xf7, 0xdf, 0x53, 0x59, 0xb8, 0x9f, 0x95, 0x85, 0xc7, 0x59, 0x59, 0xf8, 0x6b, 0x56, 0x16, 0xfe,
0x9d, 0x95, 0x85, 0x2b, 0xd1, 0xff, 0xf4, 0xfc, 0xe2, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc7,
0xae, 0x17, 0x04, 0xbf, 0x0a, 0x00, 0x00,
} }

View file

@ -20,10 +20,11 @@ service ContainerService {
} }
message CreateProcessRequest { message CreateProcessRequest {
Process process = 1; string container_id = 1;
string stdin = 2; Process process = 2;
string stdout = 3; string stdin = 3;
string stderr = 4; string stdout = 4;
string stderr = 5;
} }
message CreateProcessResponse { message CreateProcessResponse {
@ -45,6 +46,8 @@ message Process {
User user = 5; User user = 5;
string cwd = 6; string cwd = 6;
bool terminal = 7; bool terminal = 7;
Status status = 8;
uint32 exit_status = 9;
} }
enum Status { enum Status {

85
execution/container.go Normal file
View file

@ -0,0 +1,85 @@
package execution
import (
"fmt"
"os"
"path/filepath"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
type ContainerController interface {
Pause(*Container) error
Resume(*Container) error
Status(*Container) (Status, error)
Process(c *Container, pid int) (*Process, error)
Processes(*Container) ([]*Process, error)
}
func NewContainer(c ContainerController) *Container {
return &Container{
controller: c,
}
}
type Container struct {
ID string
Bundle string
Root string
controller ContainerController
processes map[int]*Process
}
func (c *Container) Process(pid int) (*Process, error) {
for _, p := range c.processes {
if p.Pid == pid {
return p, nil
}
}
return nil, fmt.Errorf("todo make real error")
}
func (c *Container) CreateProcess(spec *specs.Process) (*Process, error) {
if err := os.MkdirAll(filepath.Join(c.Root, c.getNextProcessID()), 0660); err != nil {
return nil, err
}
process := &Process{
Spec: spec,
controller: c.controller,
}
c.processes = append(c.processes, process)
return process, nil
}
func (c *Container) DeleteProcess(pid int) error {
process, ok := c.processes[pid]
if !ok {
return fmt.Errorf("it no here")
}
if process.Status() != Stopped {
return fmt.Errorf("tototoit not stopped ok?")
}
delete(c.processes, pid)
return os.RemoveAll(p.Root)
}
func (c *Container) Processes() []*Process {
var out []*Process
for _, p := range c.processes {
out = append(out, p)
}
return out
}
func (c *Container) Pause() error {
return c.controller.Pause(c)
}
func (c *Container) Resume() error {
return c.controller.Resume(c)
}
func (c *Container) Status() (Status, error) {
return c.controller.Status(c)
}

17
execution/executor.go Normal file
View file

@ -0,0 +1,17 @@
package execution
import "io"
type CreateOpts struct {
Bundle string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
type Executor interface {
Create(id string, o CreateOpts) (*Container, error)
List() ([]*Container, error)
Load(id string) (*Container, error)
Delete(string) error
}

View file

@ -0,0 +1,23 @@
package oci
import "github.com/docker/containerd/execution"
type containerController struct {
root string
}
func (c *containerController) Process(container *execution.Container, pid int) (*execution.Process, error) {
}
func (c *containerController) Processes(container *execution.Container) ([]*execution.Process, error) {
}
func (c *containerController) Pause(container *execution.Container) error {
return command(c.root, "pause", container.ID).Run()
}
func (c *containerController) Resume(container *execution.Container) error {
return command(c.root, "resume", container.ID).Run()
}

View file

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/docker/containerd" "github.com/docker/containerd"
"github.com/docker/containerd/execution"
"github.com/docker/containerd/executors" "github.com/docker/containerd/executors"
) )
@ -21,11 +22,9 @@ func init() {
executors.Register("runc", New) executors.Register("runc", New)
} }
func New() *OCIRuntime { func New(root string) *OCIRuntime {
return &OCIRuntime{ return &OCIRuntime{
root: opts.Root, root: root,
name: opts.Name,
args: opts.Args,
} }
} }
@ -33,48 +32,58 @@ type OCIRuntime struct {
// root holds runtime state information for the containers // root holds runtime state information for the containers
// launched by the runtime // launched by the runtime
root string root string
// name is the name of the runtime, i.e. runc
name string
// args specifies additional arguments to the OCI runtime
args []string
} }
func (r *OCIRuntime) Name() string { func (r *OCIRuntime) Create(id string, o execution.CreateOpts) (*execution.Container, error) {
return r.name // /run/runc/redis/1/pid
} pidFile := filepath.Join(r.root, id, "1", "pid")
cmd := command(r.root, "create",
func (r *OCIRuntime) Args() []string { "--pid-file", pidFile,
return r.args "--bundle", o.Bundle,
} id,
)
func (r *OCIRuntime) Root() string { cmd.Stdin, cmd.Stdout, cmd.Stderr = o.Stdin, o.Stdout, o.Stderr
return r.root
}
func (r *OCIRuntime) Create(c *containerd.Container) (containerd.ProcessDelegate, error) {
pidFile := fmt.Sprintf("%s/%s.pid", filepath.Join(r.root, c.ID()), "init")
cmd := r.Command("create", "--pid-file", pidFile, "--bundle", c.Path(), c.ID())
cmd.Stdin, cmd.Stdout, cmd.Stderr = c.Stdin, c.Stdout, c.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return nil, err return nil, err
} }
// TODO: kill on error
data, err := ioutil.ReadFile(pidFile) data, err := ioutil.ReadFile(pidFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }
i, err := strconv.Atoi(string(data)) pid, err := strconv.Atoi(string(data))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newProcess(i) container := execution.NewContainer(r)
container.ID = id
container.Root = filepath.Join(r.root, id)
container.Bundle = o.Bundle
process, err := container.CreateProcess(nil)
if err != nil {
return nil, err
}
process.Pid = pid
process.Stdin = o.Stdin
process.Stdout = o.Stdout
process.Stderr = o.Stderr
return container, nil
} }
func (r *OCIRuntime) Start(c *containerd.Container) error { func (r *OCIRuntime) Load(id string) (containerd.ProcessDelegate, error) {
return r.Command("start", c.ID()).Run() data, err := r.Command("state", id).Output()
if err != nil {
return nil, err
}
var s state
if err := json.Unmarshal(data, &s); err != nil {
return nil, err
}
return newProcess(s.Pid)
} }
func (r *OCIRuntime) Delete(c *containerd.Container) error { func (r *OCIRuntime) Delete(id string) error {
return r.Command("delete", c.ID()).Run() return command(r.root, "delete", id).Run()
} }
func (r *OCIRuntime) Exec(c *containerd.Container, p *containerd.Process) (containerd.ProcessDelegate, error) { func (r *OCIRuntime) Exec(c *containerd.Container, p *containerd.Process) (containerd.ProcessDelegate, error) {
@ -115,21 +124,8 @@ type state struct {
Annotations map[string]string `json:"annotations"` Annotations map[string]string `json:"annotations"`
} }
func (r *OCIRuntime) Load(id string) (containerd.ProcessDelegate, error) { func command(root, args ...string) *exec.Cmd {
data, err := r.Command("state", id).Output() return exec.Command("runc", append(
if err != nil { []string{"--root", root},
return nil, err args...)...)
}
var s state
if err := json.Unmarshal(data, &s); err != nil {
return nil, err
}
return newProcess(s.Pid)
}
func (r *OCIRuntime) Command(args ...string) *exec.Cmd {
baseArgs := append([]string{
"--root", r.root,
}, r.args...)
return exec.Command(r.name, append(baseArgs, args...)...)
} }

View file

@ -13,7 +13,7 @@ import (
"time" "time"
"github.com/docker/containerd" "github.com/docker/containerd"
"github.com/docker/containerd/execution/oci" "github.com/docker/containerd/executors/oci"
"github.com/docker/containerd/monitor" "github.com/docker/containerd/monitor"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
) )

41
execution/process.go Normal file
View file

@ -0,0 +1,41 @@
package execution
import (
"io"
"os"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
type ProcessController interface {
Start(*Process) error
Status(*Process) (Status, error)
Wait(*Process) (uint32, error)
Signal(*Process, os.Signal) error
}
type Process struct {
Pid int
Spec *specs.Process
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
controller ProcessController
}
func (p *Process) Status() (Status, error) {
return p.controller.Status(p)
}
func (p *Process) Wait() (uint32, error) {
return p.controller.Wait(p)
}
func (p *Process) Signal(s os.Signal) error {
return p.controller.Signal(p, s)
}
func (p *Process) Start() error {
return p.controller.Start(p)
}

10
execution/status.go Normal file
View file

@ -0,0 +1,10 @@
package execution
type Status string
const (
Paused Status = "paused"
Running Status = "running"
Stopped Status = "stopped"
Deleted Status = "deleted"
)

View file

@ -1,15 +0,0 @@
package containerd
import "errors"
var ErrProcessSet = errors.New("container process is already set")
type Executor interface {
List() ([]*Container, error)
Load(id string) (*Container, error)
Create(CreateOpts) (*Container, error)
Start(string) error
Delete(string) error
Exec(string, *Process) (ProcessDelegate, error)
}

View file

@ -1,120 +0,0 @@
package monitor
import (
"io"
"sync"
"syscall"
"github.com/Sirupsen/logrus"
"github.com/docker/containerd/sys"
)
type Monitorable interface {
FD() int
// Remove returns true if the monitorable should be removed
// from the event monitor under the lock of when the event was received
Remove() bool
}
type Flusher interface {
Flush() error
}
// New returns a new process monitor that emits events whenever the
// state of the fd refering to a process changes
func New() (*Monitor, error) {
fd, err := sys.EpollCreate1(0)
if err != nil {
return nil, err
}
return &Monitor{
epollFd: fd,
receivers: make(map[int]Monitorable),
events: make(chan Monitorable, 1024),
}, nil
}
type Monitor struct {
m sync.Mutex
receivers map[int]Monitorable
events chan Monitorable
epollFd int
}
// Events returns a chan that receives a Monitorable when it's FD changes state
func (m *Monitor) Events() chan Monitorable {
return m.events
}
// Add adds a process to the list of the one being monitored
func (m *Monitor) Add(ma Monitorable) error {
m.m.Lock()
defer m.m.Unlock()
fd := ma.FD()
event := syscall.EpollEvent{
Fd: int32(fd),
Events: syscall.EPOLLHUP,
}
if err := sys.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil {
return err
}
m.receivers[fd] = ma
return nil
}
// Remove deletes the Monitorable type from the monitor so that
// no other events are generated
func (m *Monitor) Remove(ma Monitorable) error {
m.m.Lock()
defer m.m.Unlock()
return m.remove(ma)
}
func (m *Monitor) remove(ma Monitorable) error {
fd := ma.FD()
delete(m.receivers, fd)
return syscall.EpollCtl(m.epollFd, syscall.EPOLL_CTL_DEL, fd, &syscall.EpollEvent{
Events: syscall.EPOLLHUP,
Fd: int32(fd),
})
}
// Close cleans up resources allocated to the Monitor
func (m *Monitor) Close() error {
return syscall.Close(m.epollFd)
}
func (m *Monitor) Run() {
var events [128]syscall.EpollEvent
for {
n, err := sys.EpollWait(m.epollFd, events[:], -1)
if err != nil {
if err == syscall.EINTR {
continue
}
logrus.WithField("error", err).Fatal("shim: epoll wait")
}
for i := 0; i < n; i++ {
fd := int(events[i].Fd)
m.m.Lock()
r := m.receivers[fd]
if f, ok := r.(Flusher); ok {
if err := f.Flush(); err != nil {
logrus.WithField("error", err).Fatal("shim: flush event FD")
}
}
if r.Remove() {
if err := m.remove(r); err != nil {
logrus.WithField("error", err).Fatal("shim: remove event FD")
}
}
if f, ok := r.(io.Closer); ok {
if err := f.Close(); err != nil {
logrus.WithField("error", err).Fatal("shim: close event FD")
}
}
m.m.Unlock()
m.events <- r
}
}
}

View file

@ -1,29 +0,0 @@
package monitor
import "errors"
func New() (*Monitor, error) {
return nil, errors.New("Monitor NewMonitor() not implemented on Solaris")
}
type Monitor struct {
}
func (m *Monitor) Events() chan Monitorable {
return nil
}
func (m *Monitor) Add(Monitorable) error {
return errors.New("Monitor Add() not implemented on Solaris")
}
func (m *Monitor) Remove(Monitorable) error {
return errors.New("Monitor Remove() not implemented on Solaris")
}
func (m *Monitor) Close() error {
return errors.New("Monitor Close() not implemented on Solaris")
}
func (m *Monitor) Run() {
}

View file

@ -1,58 +0,0 @@
package containerd
import (
"errors"
"io"
"os"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
var ErrNotExecProcess = errors.New("process not an exec process")
type ProcessDelegate interface {
Pid() int
Wait() (uint32, error)
Signal(os.Signal) error
}
type Process struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
exec bool
s *specs.Process
driver Runtime
c *Container
d ProcessDelegate
}
func (p *Process) Spec() *specs.Process {
return p.s
}
func (p *Process) Start() error {
if !p.exec {
return ErrNotExecProcess
}
d, err := p.driver.Exec(p.c, p)
if err != nil {
return err
}
p.d = d
return nil
}
func (p *Process) Pid() int {
return p.d.Pid()
}
func (p *Process) Wait() (uint32, error) {
return p.d.Wait()
}
func (p *Process) Signal(s os.Signal) error {
return p.d.Signal(s)
}

View file

@ -3,8 +3,8 @@ package execution
import ( import (
"context" "context"
"github.com/docker/containerd"
api "github.com/docker/containerd/api/execution" api "github.com/docker/containerd/api/execution"
"github.com/docker/containerd/execution"
"github.com/docker/containerd/executors" "github.com/docker/containerd/executors"
) )
@ -14,10 +14,7 @@ type Opts struct {
} }
func New(o Opts) (*Service, error) { func New(o Opts) (*Service, error) {
executor, err := executors.Get(o.Runtime)(o.Root) executor := executors.Get(o.Runtime)(o.Root)
if err != nil {
return nil, err
}
return &Service{ return &Service{
o: o, o: o,
executor: executor, executor: executor,
@ -26,7 +23,7 @@ func New(o Opts) (*Service, error) {
type Service struct { type Service struct {
o Opts o Opts
executor containerd.Executor executor execution.Executor
} }
func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) { func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
@ -36,7 +33,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateContainerRequest) (*a
return nil, err return nil, err
} }
s.supervisor.Add(container.Process()) s.supervisor.Add(container.InitProcess())
return &api.CreateContainerResponse{ return &api.CreateContainerResponse{
Container: toGRPCContainer(container), Container: toGRPCContainer(container),
@ -60,6 +57,123 @@ func (s *Service) List(ctx context.Context, r *api.ListContainerRequest) (*api.L
} }
return r, nil return r, nil
} }
func (s *Service) Get(ctx context.Context, r *api.GetContainerRequest) (*api.GetContainerResponse, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
return &api.GetContainerResponse{
Container: toGRPCContainer(container),
}, nil
}
func (s *Service) Update(ctx context.Context, r *api.UpdateContainerRequest) (*api.Empty, error) {
return nil, nil
}
func (s *Service) Pause(ctx context.Context, r *api.PauseContainerRequest) (*api.Empty, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
return nil, container.Pause()
}
func (s *Service) Resume(ctx context.Context, r *api.ResumeContainerRequest) (*api.Empty, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
return nil, container.Resume()
}
func (s *Service) CreateProcess(ctx context.Context, r *api.CreateProcessRequest) (*api.CreateProcessResponse, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
process, err := container.CreateProcess(r.Process)
if err != nil {
return nil, err
}
s.supervisor.Add(process)
r.Process.Pid = process.Pid()
return &api.CreateProcessResponse{
Process: r.Process,
}, nil
}
// containerd managed execs + system pids forked in container
func (s *Service) GetProcess(ctx context.Context, r *api.GetProcessRequest) (*api.GetProcessResponse, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
process, err := container.Process(r.ProcessId)
if err != nil {
return nil, err
}
return &api.GetProcessResponse{
Process: process,
}, nil
}
func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest) (*api.StartProcessResponse, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
process, err := container.Process(r.Process.ID)
if err != nil {
return nil, err
}
if err := process.Start(); err != nil {
return nil, err
}
return &api.StartProcessRequest{
Process: process,
}, nil
}
func (s *Service) SignalProcess(ctx context.Context, r *api.SignalProcessRequest) (*api.Empty, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
process, err := container.Process(r.Process.ID)
if err != nil {
return nil, err
}
return nil, process.Signal(r.Signal)
}
func (s *Service) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest) (*api.Empty, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
if err := container.DeleteProcess(r.Process.ID); err != nil {
return nil, err
}
return nil, nil
}
func (s *Service) ListProcesses(ctx context.Context, r *api.ListProcessesRequest) (*api.ListProcessesResponse, error) {
container, err := s.executor.Load(r.ID)
if err != nil {
return nil, err
}
processes, err := container.Processes()
if err != nil {
return nil, err
}
return &api.ListProcessesResponse{
Processes: processes,
}, nil
}
var ( var (
_ = (api.ExecutionServiceServer)(&Service{}) _ = (api.ExecutionServiceServer)(&Service{})