-
Notifications
You must be signed in to change notification settings - Fork 14
/
rivers_restart.go
58 lines (50 loc) · 1.28 KB
/
rivers_restart.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
package op
import (
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/op/common"
)
type riversRestartOp struct {
nodes []*cke.Node
upstreams []*cke.Node
params cke.ServiceParams
name string
upstreamPort int
listenPort int
pulled bool
finished bool
}
// RiversRestartOp returns an Operator to restart rivers.
func RiversRestartOp(nodes, upstreams []*cke.Node, params cke.ServiceParams, name string, upstreamPort, listenPort int) cke.Operator {
return &riversRestartOp{
nodes: nodes,
upstreams: upstreams,
params: params,
name: name,
upstreamPort: upstreamPort,
listenPort: listenPort,
}
}
func (o *riversRestartOp) Name() string {
return o.name + "-restart"
}
func (o *riversRestartOp) NextCommand() cke.Commander {
if !o.pulled {
o.pulled = true
return common.ImagePullCommand(o.nodes, cke.ToolsImage)
}
if !o.finished {
o.finished = true
return common.RunContainerCommand(o.nodes, o.name, cke.ToolsImage,
common.WithParams(RiversParams(o.upstreams, o.upstreamPort, o.listenPort)),
common.WithExtra(o.params),
common.WithRestart())
}
return nil
}
func (o *riversRestartOp) Targets() []string {
ips := make([]string, len(o.nodes))
for i, n := range o.nodes {
ips[i] = n.Address
}
return ips
}