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