-
Notifications
You must be signed in to change notification settings - Fork 14
/
proxy_boot.go
125 lines (112 loc) · 2.67 KB
/
proxy_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
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
118
119
120
121
122
123
124
125
package k8s
import (
"context"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/op"
"github.com/cybozu-go/cke/op/common"
"k8s.io/client-go/tools/clientcmd"
)
type kubeProxyBootOp struct {
nodes []*cke.Node
cluster string
params cke.ServiceParams
step int
files *common.FilesBuilder
}
// KubeProxyBootOp returns an Operator to boot kube-proxy.
func KubeProxyBootOp(nodes []*cke.Node, cluster string, params cke.ServiceParams) cke.Operator {
return &kubeProxyBootOp{
nodes: nodes,
cluster: cluster,
params: params,
files: common.NewFilesBuilder(nodes),
}
}
func (o *kubeProxyBootOp) Name() string {
return "kube-proxy-bootstrap"
}
func (o *kubeProxyBootOp) NextCommand() cke.Commander {
switch o.step {
case 0:
o.step++
return common.ImagePullCommand(o.nodes, cke.HyperkubeImage)
case 1:
o.step++
return prepareProxyFilesCommand{o.cluster, o.files}
case 2:
o.step++
return o.files
case 3:
o.step++
opts := []string{
"--tmpfs=/run",
"--privileged",
}
return common.RunContainerCommand(o.nodes, op.KubeProxyContainerName, cke.HyperkubeImage,
common.WithOpts(opts),
common.WithParams(ProxyParams()),
common.WithExtra(o.params))
default:
return nil
}
}
type prepareProxyFilesCommand struct {
cluster string
files *common.FilesBuilder
}
func (c prepareProxyFilesCommand) Run(ctx context.Context, inf cke.Infrastructure) error {
const kubeconfigPath = "/etc/kubernetes/proxy/kubeconfig"
storage := inf.Storage()
ca, err := storage.GetCACertificate(ctx, "kubernetes")
if err != nil {
return err
}
g := func(ctx context.Context, n *cke.Node) ([]byte, error) {
crt, key, err := cke.KubernetesCA{}.IssueForProxy(ctx, inf)
if err != nil {
return nil, err
}
cfg := proxyKubeconfig(c.cluster, ca, crt, key)
return clientcmd.Write(*cfg)
}
return c.files.AddFile(ctx, kubeconfigPath, g)
}
func (c prepareProxyFilesCommand) Command() cke.Command {
return cke.Command{
Name: "prepare-proxy-files",
}
}
// ProxyParams returns parameters for kube-proxy.
func ProxyParams() cke.ServiceParams {
args := []string{
"proxy",
"--proxy-mode=ipvs",
"--kubeconfig=/etc/kubernetes/proxy/kubeconfig",
}
return cke.ServiceParams{
ExtraArguments: args,
ExtraBinds: []cke.Mount{
{
Source: "/etc/machine-id",
Destination: "/etc/machine-id",
ReadOnly: true,
Propagation: "",
Label: "",
},
{
Source: "/etc/kubernetes",
Destination: "/etc/kubernetes",
ReadOnly: true,
Propagation: "",
Label: cke.LabelShared,
},
{
Source: "/lib/modules",
Destination: "/lib/modules",
ReadOnly: true,
Propagation: "",
Label: "",
},
},
}
}