Move Container and runtime to plugin pkg

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-05-11 15:24:12 -07:00
parent fa4e114979
commit 01b9f5ec67
10 changed files with 63 additions and 61 deletions

67
plugin/container.go Normal file
View File

@@ -0,0 +1,67 @@
package plugin
import "context"
type ContainerInfo struct {
ID string
Runtime string
}
type Container interface {
// Information of the container
Info() ContainerInfo
// Start the container's user defined process
Start(context.Context) error
// State returns the container's state
State(context.Context) (State, error)
// Pause pauses the container process
Pause(context.Context) error
// Resume unpauses the container process
Resume(context.Context) error
// Kill signals a container
Kill(context.Context, uint32, bool) error
// Exec adds a process into the container
Exec(context.Context, ExecOpts) (Process, error)
// Pty resizes the processes pty/console
Pty(context.Context, uint32, ConsoleSize) error
// CloseStdin closes the processes stdin
CloseStdin(context.Context, uint32) error
}
type LinuxContainer interface {
Container
}
type ExecOpts struct {
Spec []byte
IO IO
}
type Process interface {
// State returns the process state
State(context.Context) (State, error)
// Kill signals a container
Kill(context.Context, uint32, bool) error
}
type ConsoleSize struct {
Width uint32
Height uint32
}
type Status int
const (
CreatedStatus Status = iota + 1
RunningStatus
StoppedStatus
DeletedStatus
PausedStatus
)
type State interface {
// Status is the current status of the container
Status() Status
// Pid is the main process id for the container
Pid() uint32
}

View File

@@ -5,9 +5,9 @@ import "github.com/containerd/containerd"
// ContainerMonitor provides an interface for monitoring of containers within containerd
type ContainerMonitor interface {
// Monitor adds the provided container to the monitor
Monitor(containerd.Container) error
Monitor(Container) error
// Stop stops and removes the provided container from the monitor
Stop(containerd.Container) error
Stop(Container) error
// Events emits events from the monitor
Events(chan<- *containerd.Event)
}
@@ -25,11 +25,11 @@ func NewNoopMonitor() ContainerMonitor {
type noopContainerMonitor struct {
}
func (mm *noopContainerMonitor) Monitor(c containerd.Container) error {
func (mm *noopContainerMonitor) Monitor(c Container) error {
return nil
}
func (mm *noopContainerMonitor) Stop(c containerd.Container) error {
func (mm *noopContainerMonitor) Stop(c Container) error {
return nil
}
@@ -40,7 +40,7 @@ type multiContainerMonitor struct {
monitors []ContainerMonitor
}
func (mm *multiContainerMonitor) Monitor(c containerd.Container) error {
func (mm *multiContainerMonitor) Monitor(c Container) error {
for _, m := range mm.monitors {
if err := m.Monitor(c); err != nil {
return err
@@ -49,7 +49,7 @@ func (mm *multiContainerMonitor) Monitor(c containerd.Container) error {
return nil
}
func (mm *multiContainerMonitor) Stop(c containerd.Container) error {
func (mm *multiContainerMonitor) Stop(c Container) error {
for _, m := range mm.monitors {
if err := m.Stop(c); err != nil {
return err

View File

@@ -5,7 +5,6 @@ import (
"sync"
"github.com/boltdb/bolt"
"github.com/containerd/containerd"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/snapshot"
@@ -32,7 +31,7 @@ type Registration struct {
type InitContext struct {
Root string
State string
Runtimes map[string]containerd.Runtime
Runtimes map[string]Runtime
Content content.Store
Meta *bolt.DB
Snapshotter snapshot.Snapshotter

42
plugin/runtime.go Normal file
View File

@@ -0,0 +1,42 @@
package plugin
import (
"context"
"time"
"github.com/containerd/containerd"
)
type IO struct {
Stdin string
Stdout string
Stderr string
Terminal bool
}
type CreateOpts struct {
// Spec is the OCI runtime spec
Spec []byte
// Rootfs mounts to perform to gain access to the container's filesystem
Rootfs []containerd.Mount
// IO for the container's main process
IO IO
}
type Exit struct {
Status uint32
Timestamp time.Time
}
// Runtime is responsible for the creation of containers for a certain platform,
// 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)
// Containers returns all the current containers for the runtime
Containers(context.Context) ([]Container, error)
// Delete removes the container in the runtime
Delete(context.Context, Container) (*Exit, error)
// Events returns events for the runtime and all containers created by the runtime
Events(context.Context) <-chan *containerd.Event
}