-
Notifications
You must be signed in to change notification settings - Fork 14
/
rivers_boot.go
72 lines (64 loc) · 1.67 KB
/
rivers_boot.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
package op
import (
"fmt"
"strings"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/op/common"
)
type riversBootOp struct {
nodes []*cke.Node
upstreams []*cke.Node
params cke.ServiceParams
step int
name string
upstreamPort int
listenPort int
}
// RiversBootOp returns an Operator to bootstrap rivers.
func RiversBootOp(nodes, upstreams []*cke.Node, params cke.ServiceParams, name string, upstreamPort, listenPort int) cke.Operator {
return &riversBootOp{
nodes: nodes,
upstreams: upstreams,
params: params,
name: name,
upstreamPort: upstreamPort,
listenPort: listenPort,
}
}
func (o *riversBootOp) Name() string {
return o.name + "-bootstrap"
}
func (o *riversBootOp) NextCommand() cke.Commander {
switch o.step {
case 0:
o.step++
return common.ImagePullCommand(o.nodes, cke.ToolsImage)
case 1:
o.step++
return common.RunContainerCommand(o.nodes, o.name, cke.ToolsImage,
common.WithParams(RiversParams(o.upstreams, o.upstreamPort, o.listenPort)),
common.WithExtra(o.params))
default:
return nil
}
}
// RiversParams returns parameters for rivers.
func RiversParams(upstreams []*cke.Node, upstreamPort, listenPort int) cke.ServiceParams {
var ups []string
for _, n := range upstreams {
ups = append(ups, fmt.Sprintf("%s:%d", n.Address, upstreamPort))
}
args := []string{
"rivers",
"--upstreams=" + strings.Join(ups, ","),
"--listen=" + fmt.Sprintf("127.0.0.1:%d", listenPort),
}
return cke.ServiceParams{ExtraArguments: args}
}
func (o *riversBootOp) Targets() []string {
ips := make([]string, len(o.nodes))
for i, n := range o.nodes {
ips[i] = n.Address
}
return ips
}