types.go 3.8 KB

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