Move runtime interfaces to runtime package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/containerd/containerd/metadata"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/runtime"
|
||||
runc "github.com/containerd/go-runc"
|
||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/pkg/errors"
|
||||
@@ -60,7 +61,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var _ = (plugin.Runtime)(&Runtime{})
|
||||
var _ = (runtime.Runtime)(&Runtime{})
|
||||
|
||||
type Config struct {
|
||||
// Shim is a path or name of binary implementing the Shim GRPC API
|
||||
@@ -90,10 +91,10 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
remote: !cfg.NoShim,
|
||||
shim: cfg.Shim,
|
||||
runtime: cfg.Runtime,
|
||||
events: make(chan *plugin.Event, 2048),
|
||||
events: make(chan *runtime.Event, 2048),
|
||||
eventsContext: c,
|
||||
eventsCancel: cancel,
|
||||
monitor: monitor.(plugin.TaskMonitor),
|
||||
monitor: monitor.(runtime.TaskMonitor),
|
||||
tasks: newTaskList(),
|
||||
emitter: events.GetPoster(ic.Context),
|
||||
db: m.(*bolt.DB),
|
||||
@@ -121,10 +122,10 @@ type Runtime struct {
|
||||
runtime string
|
||||
remote bool
|
||||
|
||||
events chan *plugin.Event
|
||||
events chan *runtime.Event
|
||||
eventsContext context.Context
|
||||
eventsCancel func()
|
||||
monitor plugin.TaskMonitor
|
||||
monitor runtime.TaskMonitor
|
||||
tasks *taskList
|
||||
emitter events.Poster
|
||||
db *bolt.DB
|
||||
@@ -134,7 +135,7 @@ func (r *Runtime) ID() string {
|
||||
return pluginID
|
||||
}
|
||||
|
||||
func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts) (_ plugin.Task, err error) {
|
||||
func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts) (_ runtime.Task, err error) {
|
||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -216,7 +217,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts)
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Delete(ctx context.Context, c plugin.Task) (*plugin.Exit, error) {
|
||||
func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, error) {
|
||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -249,19 +250,19 @@ func (r *Runtime) Delete(ctx context.Context, c plugin.Task) (*plugin.Exit, erro
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &plugin.Exit{
|
||||
return &runtime.Exit{
|
||||
Status: rsp.ExitStatus,
|
||||
Timestamp: rsp.ExitedAt,
|
||||
Pid: rsp.Pid,
|
||||
}, bundle.Delete()
|
||||
}
|
||||
|
||||
func (r *Runtime) Tasks(ctx context.Context) ([]plugin.Task, error) {
|
||||
func (r *Runtime) Tasks(ctx context.Context) ([]runtime.Task, error) {
|
||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var o []plugin.Task
|
||||
var o []runtime.Task
|
||||
tasks, ok := r.tasks.tasks[namespace]
|
||||
if !ok {
|
||||
return o, nil
|
||||
@@ -293,7 +294,7 @@ func (r *Runtime) restoreTasks(ctx context.Context) ([]*Task, error) {
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Get(ctx context.Context, id string) (plugin.Task, error) {
|
||||
func (r *Runtime) Get(ctx context.Context, id string) (runtime.Task, error) {
|
||||
return r.tasks.get(ctx, id)
|
||||
}
|
||||
|
||||
@@ -355,25 +356,25 @@ func (r *Runtime) forward(ctx context.Context, events shim.Shim_StreamClient) {
|
||||
return
|
||||
}
|
||||
topic := ""
|
||||
var et plugin.EventType
|
||||
var et runtime.EventType
|
||||
switch e.Type {
|
||||
case shim.Event_CREATE:
|
||||
topic = "task-create"
|
||||
et = plugin.CreateEvent
|
||||
et = runtime.CreateEvent
|
||||
case shim.Event_START:
|
||||
topic = "task-start"
|
||||
et = plugin.StartEvent
|
||||
et = runtime.StartEvent
|
||||
case shim.Event_EXEC_ADDED:
|
||||
topic = "task-execadded"
|
||||
et = plugin.ExecAddEvent
|
||||
et = runtime.ExecAddEvent
|
||||
case shim.Event_OOM:
|
||||
topic = "task-oom"
|
||||
et = plugin.OOMEvent
|
||||
et = runtime.OOMEvent
|
||||
case shim.Event_EXIT:
|
||||
topic = "task-exit"
|
||||
et = plugin.ExitEvent
|
||||
et = runtime.ExitEvent
|
||||
}
|
||||
r.events <- &plugin.Event{
|
||||
r.events <- &runtime.Event{
|
||||
Timestamp: time.Now(),
|
||||
Runtime: r.ID(),
|
||||
Type: et,
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/runtime"
|
||||
"github.com/containerd/fifo"
|
||||
runc "github.com/containerd/go-runc"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@@ -369,7 +369,7 @@ func checkKillError(err error) error {
|
||||
return nil
|
||||
}
|
||||
if strings.Contains(err.Error(), "os: process already finished") || err == unix.ESRCH {
|
||||
return plugin.ErrProcessExited
|
||||
return runtime.ErrProcessExited
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/containerd/containerd/api/types/task"
|
||||
client "github.com/containerd/containerd/linux/shim"
|
||||
shim "github.com/containerd/containerd/linux/shim/v1"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/runtime"
|
||||
protobuf "github.com/gogo/protobuf/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
@@ -32,8 +32,8 @@ func newTask(id, namespace string, spec []byte, shim *client.Client) *Task {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Task) Info() plugin.TaskInfo {
|
||||
return plugin.TaskInfo{
|
||||
func (t *Task) Info() runtime.TaskInfo {
|
||||
return runtime.TaskInfo{
|
||||
ID: t.containerID,
|
||||
ContainerID: t.containerID,
|
||||
Runtime: pluginID,
|
||||
@@ -50,24 +50,24 @@ func (t *Task) Start(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *Task) State(ctx context.Context) (plugin.State, error) {
|
||||
func (t *Task) State(ctx context.Context) (runtime.State, error) {
|
||||
response, err := t.shim.State(ctx, empty)
|
||||
if err != nil {
|
||||
return plugin.State{}, errors.New(grpc.ErrorDesc(err))
|
||||
return runtime.State{}, errors.New(grpc.ErrorDesc(err))
|
||||
}
|
||||
var status plugin.Status
|
||||
var status runtime.Status
|
||||
switch response.Status {
|
||||
case task.StatusCreated:
|
||||
status = plugin.CreatedStatus
|
||||
status = runtime.CreatedStatus
|
||||
case task.StatusRunning:
|
||||
status = plugin.RunningStatus
|
||||
status = runtime.RunningStatus
|
||||
case task.StatusStopped:
|
||||
status = plugin.StoppedStatus
|
||||
status = runtime.StoppedStatus
|
||||
case task.StatusPaused:
|
||||
status = plugin.PausedStatus
|
||||
status = runtime.PausedStatus
|
||||
// TODO: containerd.DeletedStatus
|
||||
}
|
||||
return plugin.State{
|
||||
return runtime.State{
|
||||
Pid: response.Pid,
|
||||
Status: status,
|
||||
Stdin: response.Stdin,
|
||||
@@ -105,7 +105,7 @@ func (t *Task) Kill(ctx context.Context, signal uint32, pid uint32, all bool) er
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *Task) Exec(ctx context.Context, opts plugin.ExecOpts) (plugin.Process, error) {
|
||||
func (t *Task) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Process, error) {
|
||||
request := &shim.ExecProcessRequest{
|
||||
Stdin: opts.IO.Stdin,
|
||||
Stdout: opts.IO.Stdout,
|
||||
@@ -144,7 +144,7 @@ func (t *Task) Processes(ctx context.Context) ([]uint32, error) {
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
func (t *Task) ResizePty(ctx context.Context, pid uint32, size plugin.ConsoleSize) error {
|
||||
func (t *Task) ResizePty(ctx context.Context, pid uint32, size runtime.ConsoleSize) error {
|
||||
_, err := t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
|
||||
Pid: pid,
|
||||
Width: size.Width,
|
||||
@@ -178,14 +178,14 @@ func (t *Task) Checkpoint(ctx context.Context, path string, options map[string]s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) DeleteProcess(ctx context.Context, pid uint32) (*plugin.Exit, error) {
|
||||
func (t *Task) DeleteProcess(ctx context.Context, pid uint32) (*runtime.Exit, error) {
|
||||
r, err := t.shim.DeleteProcess(ctx, &shim.DeleteProcessRequest{
|
||||
Pid: pid,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(grpc.ErrorDesc(err))
|
||||
}
|
||||
return &plugin.Exit{
|
||||
return &runtime.Exit{
|
||||
Status: r.ExitStatus,
|
||||
Timestamp: r.ExitedAt,
|
||||
Pid: pid,
|
||||
@@ -218,7 +218,7 @@ func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Process) State(ctx context.Context) (plugin.State, error) {
|
||||
func (p *Process) State(ctx context.Context) (runtime.State, error) {
|
||||
// use the container status for the status of the process
|
||||
state, err := p.t.State(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user