types.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. OOMKilled bool
  32. Error error
  33. }
  34. // Backend defines callbacks that the client of the library needs to implement.
  35. type Backend interface {
  36. ProcessEvent(containerID string, event EventType, ei EventInfo) error
  37. }
  38. // Process of a container
  39. type Process interface {
  40. Delete(context.Context) (uint32, time.Time, error)
  41. }
  42. // Client provides access to containerd features.
  43. type Client interface {
  44. Version(ctx context.Context) (containerd.Version, error)
  45. Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, p Process, err error)
  46. Create(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) error
  47. Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
  48. SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal) error
  49. Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
  50. ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
  51. CloseStdin(ctx context.Context, containerID, processID string) error
  52. Pause(ctx context.Context, containerID string) error
  53. Resume(ctx context.Context, containerID string) error
  54. Stats(ctx context.Context, containerID string) (*Stats, error)
  55. ListPids(ctx context.Context, containerID string) ([]uint32, error)
  56. Summary(ctx context.Context, containerID string) ([]Summary, error)
  57. DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
  58. Delete(ctx context.Context, containerID string) error
  59. Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error)
  60. UpdateResources(ctx context.Context, containerID string, resources *Resources) error
  61. CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
  62. }
  63. // StdioCallback is called to connect a container or process stdio.
  64. type StdioCallback func(io *cio.DirectIO) (cio.IO, error)
  65. // InitProcessName is the name given to the first process of a container
  66. const InitProcessName = "init"