types.go 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package types // import "github.com/docker/docker/libcontainerd/types"
  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. // EventInfo contains the event info
  43. type EventInfo struct {
  44. ContainerID string
  45. ProcessID string
  46. Pid uint32
  47. ExitCode uint32
  48. ExitedAt time.Time
  49. OOMKilled bool
  50. Error error
  51. }
  52. // Backend defines callbacks that the client of the library needs to implement.
  53. type Backend interface {
  54. ProcessEvent(containerID string, event EventType, ei EventInfo) error
  55. }
  56. // Client provides access to containerd features.
  57. type Client interface {
  58. Version(ctx context.Context) (containerd.Version, error)
  59. Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, err error)
  60. Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
  61. Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
  62. SignalProcess(ctx context.Context, containerID, processID string, signal int) error
  63. Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
  64. ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
  65. CloseStdin(ctx context.Context, containerID, processID string) error
  66. Pause(ctx context.Context, containerID string) error
  67. Resume(ctx context.Context, containerID string) error
  68. Stats(ctx context.Context, containerID string) (*Stats, error)
  69. ListPids(ctx context.Context, containerID string) ([]uint32, error)
  70. Summary(ctx context.Context, containerID string) ([]Summary, error)
  71. DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
  72. Delete(ctx context.Context, containerID string) error
  73. Status(ctx context.Context, containerID string) (Status, error)
  74. UpdateResources(ctx context.Context, containerID string, resources *Resources) error
  75. CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
  76. }
  77. // StdioCallback is called to connect a container or process stdio.
  78. type StdioCallback func(io *cio.DirectIO) (cio.IO, error)
  79. // InitProcessName is the name given to the first process of a container
  80. const InitProcessName = "init"