Move runtime interfaces to runtime package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrContainerExists = errors.New("runtime: container with id already exists")
|
||||
ErrContainerNotExist = errors.New("runtime: container does not exist")
|
||||
ErrRuntimeNotExist = errors.New("runtime: runtime does not exist")
|
||||
ErrProcessExited = errors.New("runtime: process already exited")
|
||||
)
|
||||
@@ -1,42 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import "time"
|
||||
|
||||
type EventType int
|
||||
|
||||
func (t EventType) String() string {
|
||||
switch t {
|
||||
case ExitEvent:
|
||||
return "exit"
|
||||
case PausedEvent:
|
||||
return "paused"
|
||||
case CreateEvent:
|
||||
return "create"
|
||||
case StartEvent:
|
||||
return "start"
|
||||
case OOMEvent:
|
||||
return "oom"
|
||||
case ExecAddEvent:
|
||||
return "execAdd"
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
const (
|
||||
ExitEvent EventType = iota + 1
|
||||
PausedEvent
|
||||
CreateEvent
|
||||
StartEvent
|
||||
OOMEvent
|
||||
ExecAddEvent
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Timestamp time.Time
|
||||
Type EventType
|
||||
Runtime string
|
||||
ID string
|
||||
Pid uint32
|
||||
ExitStatus uint32
|
||||
ExitedAt time.Time
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package plugin
|
||||
|
||||
// TaskMonitor provides an interface for monitoring of containers within containerd
|
||||
type TaskMonitor interface {
|
||||
// Monitor adds the provided container to the monitor
|
||||
Monitor(Task) error
|
||||
// Stop stops and removes the provided container from the monitor
|
||||
Stop(Task) error
|
||||
// Events emits events from the monitor
|
||||
Events(chan<- *Event)
|
||||
}
|
||||
|
||||
func NewMultiTaskMonitor(monitors ...TaskMonitor) TaskMonitor {
|
||||
return &multiTaskMonitor{
|
||||
monitors: monitors,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNoopMonitor() TaskMonitor {
|
||||
return &noopTaskMonitor{}
|
||||
}
|
||||
|
||||
type noopTaskMonitor struct {
|
||||
}
|
||||
|
||||
func (mm *noopTaskMonitor) Monitor(c Task) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *noopTaskMonitor) Stop(c Task) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *noopTaskMonitor) Events(events chan<- *Event) {
|
||||
}
|
||||
|
||||
type multiTaskMonitor struct {
|
||||
monitors []TaskMonitor
|
||||
}
|
||||
|
||||
func (mm *multiTaskMonitor) Monitor(c Task) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Monitor(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *multiTaskMonitor) Stop(c Task) error {
|
||||
for _, m := range mm.monitors {
|
||||
if err := m.Stop(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mm *multiTaskMonitor) Events(events chan<- *Event) {
|
||||
for _, m := range mm.monitors {
|
||||
m.Events(events)
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
)
|
||||
|
||||
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 []mount.Mount
|
||||
// IO for the container's main process
|
||||
IO IO
|
||||
Checkpoint string
|
||||
}
|
||||
|
||||
type Exit struct {
|
||||
Pid uint32
|
||||
Status uint32
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
// Runtime is responsible for the creation of containers for a certain platform,
|
||||
// arch, or custom usage.
|
||||
type Runtime interface {
|
||||
// ID of the runtime
|
||||
ID() string
|
||||
// Create creates a task with the provided id and options.
|
||||
Create(ctx context.Context, id string, opts CreateOpts) (Task, error)
|
||||
// Get returns a task.
|
||||
Get(context.Context, string) (Task, error)
|
||||
// Tasks returns all the current tasks for the runtime.
|
||||
// Any container runs at most one task at a time.
|
||||
Tasks(context.Context) ([]Task, error)
|
||||
// Delete removes the task in the runtime.
|
||||
Delete(context.Context, Task) (*Exit, error)
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import "context"
|
||||
|
||||
type TaskInfo struct {
|
||||
ID string
|
||||
ContainerID string
|
||||
Runtime string
|
||||
Spec []byte
|
||||
Namespace string
|
||||
}
|
||||
|
||||
type Task interface {
|
||||
// Information of the container
|
||||
Info() TaskInfo
|
||||
// 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, uint32, bool) error
|
||||
// Exec adds a process into the container
|
||||
Exec(context.Context, ExecOpts) (Process, error)
|
||||
// Processes returns all pids for the container
|
||||
Processes(context.Context) ([]uint32, error)
|
||||
// Pty resizes the processes pty/console
|
||||
ResizePty(context.Context, uint32, ConsoleSize) error
|
||||
// CloseStdin closes the processes stdin
|
||||
CloseIO(context.Context, uint32) error
|
||||
// Checkpoint checkpoints a container to an image with live system data
|
||||
Checkpoint(context.Context, string, map[string]string) error
|
||||
// DeleteProcess deletes a specific exec process via the pid
|
||||
DeleteProcess(context.Context, uint32) (*Exit, error)
|
||||
// Update sets the provided resources to a running task
|
||||
Update(context.Context, []byte) error
|
||||
}
|
||||
|
||||
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 struct {
|
||||
// Status is the current status of the container
|
||||
Status Status
|
||||
// Pid is the main process id for the container
|
||||
Pid uint32
|
||||
Stdin string
|
||||
Stdout string
|
||||
Stderr string
|
||||
Terminal bool
|
||||
}
|
||||
Reference in New Issue
Block a user