types.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package libcontainerd
  2. import (
  3. "context"
  4. "time"
  5. "github.com/containerd/containerd"
  6. "github.com/containerd/containerd/cio"
  7. "github.com/opencontainers/runtime-spec/specs-go"
  8. )
  9. // EventType represents a possible event from libcontainerd
  10. type EventType string
  11. // Event constants used when reporting events
  12. const (
  13. EventUnknown EventType = "unknown"
  14. EventExit EventType = "exit"
  15. EventOOM EventType = "oom"
  16. EventCreate EventType = "create"
  17. EventStart EventType = "start"
  18. EventExecAdded EventType = "exec-added"
  19. EventExecStarted EventType = "exec-started"
  20. EventPaused EventType = "paused"
  21. EventResumed EventType = "resumed"
  22. )
  23. // Status represents the current status of a container
  24. type Status string
  25. // Possible container statuses
  26. const (
  27. // Running indicates the process is currently executing
  28. StatusRunning Status = "running"
  29. // Created indicates the process has been created within containerd but the
  30. // user's defined process has not started
  31. StatusCreated Status = "created"
  32. // Stopped indicates that the process has ran and exited
  33. StatusStopped Status = "stopped"
  34. // Paused indicates that the process is currently paused
  35. StatusPaused Status = "paused"
  36. // Pausing indicates that the process is currently switching from a
  37. // running state into a paused state
  38. StatusPausing Status = "pausing"
  39. // Unknown indicates that we could not determine the status from the runtime
  40. StatusUnknown Status = "unknown"
  41. )
  42. // Remote on Linux defines the accesspoint to the containerd grpc API.
  43. // Remote on Windows is largely an unimplemented interface as there is
  44. // no remote containerd.
  45. type Remote interface {
  46. // Client returns a new Client instance connected with given Backend.
  47. NewClient(namespace string, backend Backend) (Client, error)
  48. // Cleanup stops containerd if it was started by libcontainerd.
  49. // Note this is not used on Windows as there is no remote containerd.
  50. Cleanup()
  51. }
  52. // RemoteOption allows to configure parameters of remotes.
  53. // This is unused on Windows.
  54. type RemoteOption interface {
  55. Apply(Remote) error
  56. }
  57. // EventInfo contains the event info
  58. type EventInfo struct {
  59. ContainerID string
  60. ProcessID string
  61. Pid uint32
  62. ExitCode uint32
  63. ExitedAt time.Time
  64. OOMKilled bool
  65. // Windows Only field
  66. UpdatePending bool
  67. }
  68. // Backend defines callbacks that the client of the library needs to implement.
  69. type Backend interface {
  70. ProcessEvent(containerID string, event EventType, ei EventInfo) error
  71. }
  72. // Client provides access to containerd features.
  73. type Client interface {
  74. Version(ctx context.Context) (containerd.Version, error)
  75. Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, err error)
  76. Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
  77. Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
  78. SignalProcess(ctx context.Context, containerID, processID string, signal int) error
  79. Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
  80. ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
  81. CloseStdin(ctx context.Context, containerID, processID string) error
  82. Pause(ctx context.Context, containerID string) error
  83. Resume(ctx context.Context, containerID string) error
  84. Stats(ctx context.Context, containerID string) (*Stats, error)
  85. ListPids(ctx context.Context, containerID string) ([]uint32, error)
  86. Summary(ctx context.Context, containerID string) ([]Summary, error)
  87. DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
  88. Delete(ctx context.Context, containerID string) error
  89. Status(ctx context.Context, containerID string) (Status, error)
  90. UpdateResources(ctx context.Context, containerID string, resources *Resources) error
  91. CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
  92. }
  93. // StdioCallback is called to connect a container or process stdio.
  94. type StdioCallback func(io *cio.DirectIO) (cio.IO, error)