-
Notifications
You must be signed in to change notification settings - Fork 14
/
op.go
117 lines (98 loc) · 2.69 KB
/
op.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package localproxy
import (
"context"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/op/common"
)
type unboundBootOp struct {
conf []byte
step int
}
var localNode = &cke.Node{
Address: "localhost",
}
var ckeNodes = []*cke.Node{localNode}
var _ cke.Operator = &unboundBootOp{}
const unboundContainerName = "cke-unbound"
// Name returns the operation name.
func (o *unboundBootOp) Name() string {
return "unbound-boot-op"
}
// NextCommand returns the next command or nil if completed.
func (o *unboundBootOp) NextCommand() cke.Commander {
defer func() { o.step++ }()
switch o.step {
case 0:
return common.ImagePullCommand(ckeNodes, cke.UnboundImage)
case 1:
files := common.NewFilesBuilder(ckeNodes)
files.AddFile(context.Background(), "/etc/unbound/unbound.conf", func(context.Context, *cke.Node) ([]byte, error) {
return o.conf, nil
})
return files
case 2:
return common.RunContainerCommand(ckeNodes, unboundContainerName, cke.UnboundImage,
common.WithOpts([]string{"--cap-add=NET_BIND_SERVICE"}),
common.WithParams(cke.ServiceParams{
ExtraArguments: []string{"-c", "/etc/unbound/unbound.conf"},
ExtraBinds: []cke.Mount{
{
Source: "/etc/unbound",
Destination: "/etc/unbound",
ReadOnly: true,
},
},
}),
)
default:
return nil
}
}
// Targets returns the ip which will be affected by the operation
func (o *unboundBootOp) Targets() []string {
return []string{"localhost"}
}
type unboundRestartOp struct {
conf []byte
step int
}
var _ cke.Operator = &unboundRestartOp{}
// Name returns the operation name.
func (o *unboundRestartOp) Name() string {
return "unbound-restart-op"
}
// NextCommand returns the next command or nil if completed.
func (o *unboundRestartOp) NextCommand() cke.Commander {
defer func() { o.step++ }()
switch o.step {
case 0:
return common.ImagePullCommand(ckeNodes, cke.UnboundImage)
case 1:
files := common.NewFilesBuilder(ckeNodes)
files.AddFile(context.Background(), "/etc/unbound/unbound.conf", func(context.Context, *cke.Node) ([]byte, error) {
return o.conf, nil
})
return files
case 2:
return common.RunContainerCommand(ckeNodes, unboundContainerName, cke.UnboundImage,
common.WithOpts([]string{"--cap-add=NET_BIND_SERVICE"}),
common.WithParams(cke.ServiceParams{
ExtraArguments: []string{"-c", "/etc/unbound/unbound.conf"},
ExtraBinds: []cke.Mount{
{
Source: "/etc/unbound",
Destination: "/etc/unbound",
ReadOnly: true,
},
},
}),
common.WithRestart(),
)
default:
return nil
}
}
// Targets returns the ip which will be affected by the operation
func (o *unboundRestartOp) Targets() []string {
return []string{"localhost"}
}