types.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. specs "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. // EventInfo contains the event info
  24. type EventInfo struct {
  25. ContainerID string
  26. ProcessID string
  27. Pid uint32
  28. ExitCode uint32
  29. ExitedAt time.Time
  30. OOMKilled bool
  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. Delete(context.Context) (uint32, time.Time, error)
  40. }
  41. // Client provides access to containerd features.
  42. type Client interface {
  43. Version(ctx context.Context) (containerd.Version, error)
  44. Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, p Process, err error)
  45. Create(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) error
  46. Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
  47. SignalProcess(ctx context.Context, containerID, processID string, signal int) error
  48. Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
  49. ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
  50. CloseStdin(ctx context.Context, containerID, processID string) error
  51. Pause(ctx context.Context, containerID string) error
  52. Resume(ctx context.Context, containerID string) error
  53. Stats(ctx context.Context, containerID string) (*Stats, error)
  54. ListPids(ctx context.Context, containerID string) ([]uint32, error)
  55. Summary(ctx context.Context, containerID string) ([]Summary, error)
  56. DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
  57. Delete(ctx context.Context, containerID string) error
  58. Status(ctx context.Context, containerID string) (containerd.ProcessStatus, error)
  59. UpdateResources(ctx context.Context, containerID string, resources *Resources) error
  60. CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
  61. }
  62. // StdioCallback is called to connect a container or process stdio.
  63. type StdioCallback func(io *cio.DirectIO) (cio.IO, error)
  64. // InitProcessName is the name given to the first process of a container
  65. const InitProcessName = "init"