api/services: define the container metadata service

Working from feedback on the existing implementation, we have now
introduced a central metadata object to represent the lifecycle and pin
the resources required to implement what people today know as
containers. This includes the runtime specification and the root
filesystem snapshots. We also allow arbitrary labeling of the container.
Such provisions will bring the containerd definition of container closer
to what is expected by users.

The objects that encompass today's ContainerService, centered around the
runtime, will be known as tasks. These tasks take on the existing
lifecycle behavior of containerd's containers, which means that they are
deleted when they exit. Largely, there are no other changes except for
naming.

The `Container` object will operate purely as a metadata object. No
runtime state will be held on `Container`. It only informs the execution
service on what is required for creating tasks and the resources in use
by that container. The resources referenced by that container will be
deleted when the container is deleted, if not in use. In this sense,
users can create, list, label and delete containers in a similar way as
they do with docker today, without the complexity of runtime locks that
plagues current implementations.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-05-15 17:44:50 -07:00
parent 8f3b89c79d
commit 539742881d
47 changed files with 4067 additions and 1115 deletions

View File

@@ -4,7 +4,7 @@ import (
"path/filepath"
shimapi "github.com/containerd/containerd/api/services/shim"
"github.com/containerd/containerd/api/types/container"
"github.com/containerd/containerd/api/types/task"
runc "github.com/containerd/go-runc"
google_protobuf "github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
@@ -104,11 +104,11 @@ func (c *client) Checkpoint(ctx context.Context, in *shimapi.CheckpointRequest,
}
type events struct {
c chan *container.Event
c chan *task.Event
ctx context.Context
}
func (e *events) Recv() (*container.Event, error) {
func (e *events) Recv() (*task.Event, error) {
ev := <-e.c
return ev, nil
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/containerd/console"
shimapi "github.com/containerd/containerd/api/services/shim"
"github.com/containerd/containerd/api/types/container"
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/reaper"
google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
@@ -25,7 +25,7 @@ func New(path string) *Service {
return &Service{
path: path,
processes: make(map[int]process),
events: make(chan *container.Event, 4096),
events: make(chan *task.Event, 4096),
}
}
@@ -36,7 +36,7 @@ type Service struct {
bundle string
mu sync.Mutex
processes map[int]process
events chan *container.Event
events chan *task.Event
execID int
}
@@ -56,8 +56,9 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateRequest) (*shimap
ExitCh: make(chan int, 1),
}
reaper.Default.Register(pid, cmd)
s.events <- &container.Event{
Type: container.Event_CREATE,
go s.waitExit(process, pid, cmd)
s.events <- &task.Event{
Type: task.Event_CREATE,
ID: r.ID,
Pid: uint32(pid),
}
@@ -71,8 +72,8 @@ func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*google_p
if err := s.initProcess.Start(ctx); err != nil {
return nil, err
}
s.events <- &container.Event{
Type: container.Event_START,
s.events <- &task.Event{
Type: task.Event_START,
ID: s.id,
Pid: uint32(s.initProcess.Pid()),
}
@@ -114,8 +115,9 @@ func (s *Service) Exec(ctx context.Context, r *shimapi.ExecRequest) (*shimapi.Ex
}
reaper.Default.RegisterNL(pid, cmd)
reaper.Default.Unlock()
s.events <- &container.Event{
Type: container.Event_EXEC_ADDED,
go s.waitExit(process, pid, cmd)
s.events <- &task.Event{
Type: task.Event_EXEC_ADDED,
ID: s.id,
Pid: uint32(pid),
}
@@ -159,35 +161,35 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
if err != nil {
return nil, err
}
status := container.StatusUnknown
status := task.StatusUnknown
switch st {
case "created":
status = container.StatusCreated
status = task.StatusCreated
case "running":
status = container.StatusRunning
status = task.StatusRunning
case "stopped":
status = container.StatusStopped
status = task.StatusStopped
case "paused":
status = container.StatusPaused
status = task.StatusPaused
}
o := &shimapi.StateResponse{
ID: s.id,
Bundle: s.bundle,
Pid: uint32(s.initProcess.Pid()),
Status: status,
Processes: []*container.Process{},
Processes: []*task.Process{},
}
s.mu.Lock()
defer s.mu.Unlock()
for _, p := range s.processes {
status := container.StatusRunning
status := task.StatusRunning
if err := unix.Kill(p.Pid(), 0); err != nil {
if err != syscall.ESRCH {
return nil, err
}
status = container.StatusStopped
status = task.StatusStopped
}
o.Processes = append(o.Processes, &container.Process{
o.Processes = append(o.Processes, &task.Process{
Pid: uint32(p.Pid()),
Status: status,
})
@@ -255,9 +257,9 @@ func (s *Service) Processes(ctx context.Context, r *shimapi.ProcessesRequest) (*
return nil, err
}
ps := []*container.Process{}
ps := []*task.Process{}
for _, pid := range pids {
ps = append(ps, &container.Process{
ps = append(ps, &task.Process{
Pid: pid,
})
}
@@ -290,8 +292,8 @@ func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointRequest)
func (s *Service) waitExit(p process, pid int, cmd *reaper.Cmd) {
status := <-cmd.ExitCh
p.Exited(status)
s.events <- &container.Event{
Type: container.Event_EXIT,
s.events <- &task.Event{
Type: task.Event_EXIT,
ID: s.id,
Pid: uint32(pid),
ExitStatus: uint32(status),