2018-02-05 16:05:59 -05:00
|
|
|
package libcontainerd // import "github.com/docker/docker/libcontainerd"
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2016-07-15 17:12:07 -04:00
|
|
|
import (
|
2017-09-22 09:52:41 -04:00
|
|
|
"context"
|
|
|
|
"time"
|
2016-07-15 17:12:07 -04:00
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
"github.com/containerd/containerd"
|
2017-11-29 19:15:20 -05:00
|
|
|
"github.com/containerd/containerd/cio"
|
2016-09-27 13:26:59 -04:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2016-07-15 17:12:07 -04:00
|
|
|
)
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
// EventType represents a possible event from libcontainerd
|
|
|
|
type EventType string
|
|
|
|
|
|
|
|
// Event constants used when reporting events
|
|
|
|
const (
|
|
|
|
EventUnknown EventType = "unknown"
|
|
|
|
EventExit EventType = "exit"
|
|
|
|
EventOOM EventType = "oom"
|
|
|
|
EventCreate EventType = "create"
|
|
|
|
EventStart EventType = "start"
|
|
|
|
EventExecAdded EventType = "exec-added"
|
|
|
|
EventExecStarted EventType = "exec-started"
|
|
|
|
EventPaused EventType = "paused"
|
|
|
|
EventResumed EventType = "resumed"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Status represents the current status of a container
|
|
|
|
type Status string
|
|
|
|
|
|
|
|
// Possible container statuses
|
2016-03-18 14:50:19 -04:00
|
|
|
const (
|
2017-09-22 09:52:41 -04:00
|
|
|
// Running indicates the process is currently executing
|
|
|
|
StatusRunning Status = "running"
|
|
|
|
// Created indicates the process has been created within containerd but the
|
|
|
|
// user's defined process has not started
|
|
|
|
StatusCreated Status = "created"
|
|
|
|
// Stopped indicates that the process has ran and exited
|
|
|
|
StatusStopped Status = "stopped"
|
|
|
|
// Paused indicates that the process is currently paused
|
|
|
|
StatusPaused Status = "paused"
|
|
|
|
// Pausing indicates that the process is currently switching from a
|
|
|
|
// running state into a paused state
|
|
|
|
StatusPausing Status = "pausing"
|
|
|
|
// Unknown indicates that we could not determine the status from the runtime
|
|
|
|
StatusUnknown Status = "unknown"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
// Remote on Linux defines the accesspoint to the containerd grpc API.
|
|
|
|
// Remote on Windows is largely an unimplemented interface as there is
|
|
|
|
// no remote containerd.
|
|
|
|
type Remote interface {
|
|
|
|
// Client returns a new Client instance connected with given Backend.
|
|
|
|
NewClient(namespace string, backend Backend) (Client, error)
|
|
|
|
// Cleanup stops containerd if it was started by libcontainerd.
|
|
|
|
// Note this is not used on Windows as there is no remote containerd.
|
|
|
|
Cleanup()
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoteOption allows to configure parameters of remotes.
|
|
|
|
// This is unused on Windows.
|
|
|
|
type RemoteOption interface {
|
|
|
|
Apply(Remote) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventInfo contains the event info
|
|
|
|
type EventInfo struct {
|
|
|
|
ContainerID string
|
|
|
|
ProcessID string
|
|
|
|
Pid uint32
|
|
|
|
ExitCode uint32
|
|
|
|
ExitedAt time.Time
|
|
|
|
OOMKilled bool
|
|
|
|
// Windows Only field
|
|
|
|
UpdatePending bool
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Backend defines callbacks that the client of the library needs to implement.
|
|
|
|
type Backend interface {
|
2017-09-22 09:52:41 -04:00
|
|
|
ProcessEvent(containerID string, event EventType, ei EventInfo) error
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Client provides access to containerd features.
|
|
|
|
type Client interface {
|
2017-11-02 20:21:18 -04:00
|
|
|
Version(ctx context.Context) (containerd.Version, error)
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, err error)
|
|
|
|
|
|
|
|
Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
|
|
|
|
Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
|
|
|
|
SignalProcess(ctx context.Context, containerID, processID string, signal int) error
|
|
|
|
Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
|
|
|
|
ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
|
|
|
|
CloseStdin(ctx context.Context, containerID, processID string) error
|
|
|
|
Pause(ctx context.Context, containerID string) error
|
|
|
|
Resume(ctx context.Context, containerID string) error
|
|
|
|
Stats(ctx context.Context, containerID string) (*Stats, error)
|
|
|
|
ListPids(ctx context.Context, containerID string) ([]uint32, error)
|
|
|
|
Summary(ctx context.Context, containerID string) ([]Summary, error)
|
|
|
|
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
|
|
|
|
Delete(ctx context.Context, containerID string) error
|
|
|
|
Status(ctx context.Context, containerID string) (Status, error)
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
UpdateResources(ctx context.Context, containerID string, resources *Resources) error
|
|
|
|
CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-10-17 17:39:52 -04:00
|
|
|
// StdioCallback is called to connect a container or process stdio.
|
2017-12-07 14:26:27 -05:00
|
|
|
type StdioCallback func(io *cio.DirectIO) (cio.IO, error)
|