attachment.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package container // import "github.com/docker/docker/daemon/cluster/executor/container"
  2. import (
  3. "context"
  4. executorpkg "github.com/docker/docker/daemon/cluster/executor"
  5. "github.com/moby/swarmkit/v2/agent/exec"
  6. "github.com/moby/swarmkit/v2/api"
  7. )
  8. // networkAttacherController implements agent.Controller against docker's API.
  9. //
  10. // networkAttacherController manages the lifecycle of network
  11. // attachment of a docker unmanaged container managed as a task from
  12. // agent point of view. It provides network attachment information to
  13. // the unmanaged container for it to attach to the network and run.
  14. type networkAttacherController struct {
  15. backend executorpkg.Backend
  16. task *api.Task
  17. adapter *containerAdapter
  18. closed chan struct{}
  19. }
  20. func newNetworkAttacherController(b executorpkg.Backend, i executorpkg.ImageBackend, v executorpkg.VolumeBackend, task *api.Task, node *api.NodeDescription, dependencies exec.DependencyGetter) (*networkAttacherController, error) {
  21. adapter, err := newContainerAdapter(b, i, v, task, node, dependencies)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return &networkAttacherController{
  26. backend: b,
  27. task: task,
  28. adapter: adapter,
  29. closed: make(chan struct{}),
  30. }, nil
  31. }
  32. func (nc *networkAttacherController) Update(ctx context.Context, t *api.Task) error {
  33. return nil
  34. }
  35. func (nc *networkAttacherController) Prepare(ctx context.Context) error {
  36. // Make sure all the networks that the task needs are created.
  37. return nc.adapter.createNetworks(ctx)
  38. }
  39. func (nc *networkAttacherController) Start(ctx context.Context) error {
  40. return nc.adapter.networkAttach(ctx)
  41. }
  42. func (nc *networkAttacherController) Wait(pctx context.Context) error {
  43. ctx, cancel := context.WithCancel(pctx)
  44. defer cancel()
  45. return nc.adapter.waitForDetach(ctx)
  46. }
  47. func (nc *networkAttacherController) Shutdown(ctx context.Context) error {
  48. return nil
  49. }
  50. func (nc *networkAttacherController) Terminate(ctx context.Context) error {
  51. return nil
  52. }
  53. func (nc *networkAttacherController) Remove(ctx context.Context) error {
  54. // Try removing the network referenced in this task in case this
  55. // task is the last one referencing it
  56. return nc.adapter.removeNetworks(ctx)
  57. }
  58. func (nc *networkAttacherController) Close() error {
  59. return nil
  60. }