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:
@@ -2,15 +2,16 @@ package plugin
|
||||
|
||||
import "context"
|
||||
|
||||
type ContainerInfo struct {
|
||||
ID string
|
||||
Runtime string
|
||||
Spec []byte
|
||||
type TaskInfo struct {
|
||||
ID string
|
||||
ContainerID string
|
||||
Runtime string
|
||||
Spec []byte
|
||||
}
|
||||
|
||||
type Container interface {
|
||||
type Task interface {
|
||||
// Information of the container
|
||||
Info() ContainerInfo
|
||||
Info() TaskInfo
|
||||
// Start the container's user defined process
|
||||
Start(context.Context) error
|
||||
// State returns the container's state
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
package plugin
|
||||
|
||||
// ContainerMonitor provides an interface for monitoring of containers within containerd
|
||||
type ContainerMonitor interface {
|
||||
// TaskMonitor provides an interface for monitoring of containers within containerd
|
||||
type TaskMonitor interface {
|
||||
// Monitor adds the provided container to the monitor
|
||||
Monitor(Container) error
|
||||
Monitor(Task) error
|
||||
// Stop stops and removes the provided container from the monitor
|
||||
Stop(Container) error
|
||||
Stop(Task) error
|
||||
// Events emits events from the monitor
|
||||
Events(chan<- *Event)
|
||||
}
|
||||
|
||||
func NewMultiContainerMonitor(monitors ...ContainerMonitor) ContainerMonitor {
|
||||
return &multiContainerMonitor{
|
||||
func NewMultiTaskMonitor(monitors ...TaskMonitor) TaskMonitor {
|
||||
return &multiTaskMonitor{
|
||||
monitors: monitors,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNoopMonitor() ContainerMonitor {
|
||||
return &noopContainerMonitor{}
|
||||
func NewNoopMonitor() TaskMonitor {
|
||||
return &noopTaskMonitor{}
|
||||
}
|
||||
|
||||
type noopContainerMonitor struct {
|
||||
type noopTaskMonitor struct {
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Monitor(c Container) error {
|
||||
func (mm *noopTaskMonitor) Monitor(c Task) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Stop(c Container) error {
|
||||
func (mm *noopTaskMonitor) Stop(c Task) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *noopContainerMonitor) Events(events chan<- *Event) {
|
||||
func (mm *noopTaskMonitor) Events(events chan<- *Event) {
|
||||
}
|
||||
|
||||
type multiContainerMonitor struct {
|
||||
monitors []ContainerMonitor
|
||||
type multiTaskMonitor struct {
|
||||
monitors []TaskMonitor
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Monitor(c Container) error {
|
||||
func (mm *multiTaskMonitor) Monitor(c Task) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Monitor(c); err != nil {
|
||||
return err
|
||||
@@ -47,7 +47,7 @@ func (mm *multiContainerMonitor) Monitor(c Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Stop(c Container) error {
|
||||
func (mm *multiTaskMonitor) Stop(c Task) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Stop(c); err != nil {
|
||||
return err
|
||||
@@ -56,7 +56,7 @@ func (mm *multiContainerMonitor) Stop(c Container) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *multiContainerMonitor) Events(events chan<- *Event) {
|
||||
func (mm *multiTaskMonitor) Events(events chan<- *Event) {
|
||||
for _, m := range mm.monitors {
|
||||
m.Events(events)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
RuntimePlugin PluginType = iota + 1
|
||||
GRPCPlugin
|
||||
SnapshotPlugin
|
||||
ContainerMonitorPlugin
|
||||
TaskMonitorPlugin
|
||||
)
|
||||
|
||||
type Registration struct {
|
||||
@@ -37,7 +37,7 @@ type InitContext struct {
|
||||
Snapshotter snapshot.Snapshotter
|
||||
Config interface{}
|
||||
Context context.Context
|
||||
Monitor ContainerMonitor
|
||||
Monitor TaskMonitor
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
|
||||
@@ -33,11 +33,11 @@ type Exit struct {
|
||||
// arch, or custom usage.
|
||||
type Runtime interface {
|
||||
// Create creates a container with the provided id and options
|
||||
Create(ctx context.Context, id string, opts CreateOpts) (Container, error)
|
||||
Create(ctx context.Context, id string, opts CreateOpts) (Task, error)
|
||||
// Containers returns all the current containers for the runtime
|
||||
Containers(context.Context) ([]Container, error)
|
||||
Tasks(context.Context) ([]Task, error)
|
||||
// Delete removes the container in the runtime
|
||||
Delete(context.Context, Container) (*Exit, error)
|
||||
Delete(context.Context, Task) (*Exit, error)
|
||||
// Events returns events for the runtime and all containers created by the runtime
|
||||
Events(context.Context) <-chan *Event
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user