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