github.com/moby/docker@v26.1.3+incompatible/libcontainerd/types/types.go (about)

     1  package types // import "github.com/docker/docker/libcontainerd/types"
     2  
     3  import (
     4  	"context"
     5  	"syscall"
     6  	"time"
     7  
     8  	"github.com/containerd/containerd"
     9  	"github.com/containerd/containerd/cio"
    10  	specs "github.com/opencontainers/runtime-spec/specs-go"
    11  )
    12  
    13  // EventType represents a possible event from libcontainerd
    14  type EventType string
    15  
    16  // Event constants used when reporting events
    17  const (
    18  	EventUnknown     EventType = "unknown"
    19  	EventExit        EventType = "exit"
    20  	EventOOM         EventType = "oom"
    21  	EventCreate      EventType = "create"
    22  	EventStart       EventType = "start"
    23  	EventExecAdded   EventType = "exec-added"
    24  	EventExecStarted EventType = "exec-started"
    25  	EventPaused      EventType = "paused"
    26  	EventResumed     EventType = "resumed"
    27  )
    28  
    29  // EventInfo contains the event info
    30  type EventInfo struct {
    31  	ContainerID string
    32  	ProcessID   string
    33  	Pid         uint32
    34  	ExitCode    uint32
    35  	ExitedAt    time.Time
    36  	Error       error
    37  }
    38  
    39  // Backend defines callbacks that the client of the library needs to implement.
    40  type Backend interface {
    41  	ProcessEvent(containerID string, event EventType, ei EventInfo) error
    42  }
    43  
    44  // Process of a container
    45  type Process interface {
    46  	// Pid is the system specific process id
    47  	Pid() uint32
    48  	// Kill sends the provided signal to the process
    49  	Kill(ctx context.Context, signal syscall.Signal) error
    50  	// Resize changes the width and height of the process's terminal
    51  	Resize(ctx context.Context, width, height uint32) error
    52  	// Delete removes the process and any resources allocated returning the exit status
    53  	Delete(context.Context) (*containerd.ExitStatus, error)
    54  }
    55  
    56  // Client provides access to containerd features.
    57  type Client interface {
    58  	Version(ctx context.Context) (containerd.Version, error)
    59  	// LoadContainer loads the metadata for a container from containerd.
    60  	LoadContainer(ctx context.Context, containerID string) (Container, error)
    61  	// NewContainer creates a new containerd container.
    62  	NewContainer(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) (Container, error)
    63  }
    64  
    65  // Container provides access to a containerd container.
    66  type Container interface {
    67  	NewTask(ctx context.Context, checkpointDir string, withStdin bool, attachStdio StdioCallback) (Task, error)
    68  	Task(ctx context.Context) (Task, error)
    69  	// AttachTask returns the current task for the container and reattaches
    70  	// to the IO for the running task. If no task exists for the container
    71  	// a NotFound error is returned.
    72  	//
    73  	// Clients must make sure that only one reader is attached to the task.
    74  	AttachTask(ctx context.Context, attachStdio StdioCallback) (Task, error)
    75  	// Delete removes the container and associated resources
    76  	Delete(context.Context) error
    77  }
    78  
    79  // Task provides access to a running containerd container.
    80  type Task interface {
    81  	Process
    82  	// Start begins execution of the task
    83  	Start(context.Context) error
    84  	// Pause suspends the execution of the task
    85  	Pause(context.Context) error
    86  	// Resume the execution of the task
    87  	Resume(context.Context) error
    88  	Stats(ctx context.Context) (*Stats, error)
    89  	// Pids returns a list of system specific process ids inside the task
    90  	Pids(context.Context) ([]containerd.ProcessInfo, error)
    91  	Summary(ctx context.Context) ([]Summary, error)
    92  	// ForceDelete forcefully kills the task's processes and deletes the task
    93  	ForceDelete(context.Context) error
    94  	// Status returns the executing status of the task
    95  	Status(ctx context.Context) (containerd.Status, error)
    96  	// Exec creates and starts a new process inside the task
    97  	Exec(ctx context.Context, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (Process, error)
    98  	UpdateResources(ctx context.Context, resources *Resources) error
    99  	CreateCheckpoint(ctx context.Context, checkpointDir string, exit bool) error
   100  }
   101  
   102  // StdioCallback is called to connect a container or process stdio.
   103  type StdioCallback func(io *cio.DirectIO) (cio.IO, error)