-
Notifications
You must be signed in to change notification settings - Fork 15
/
scheduler_boot.go
116 lines (103 loc) · 2.65 KB
/
scheduler_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
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 schedulerBootOp struct {
nodes []*cke.Node
cluster string
params cke.ServiceParams
step int
files *common.FilesBuilder
}
// SchedulerBootOp returns an Operator to bootstrap kube-scheduler
func SchedulerBootOp(nodes []*cke.Node, cluster string, params cke.ServiceParams) cke.Operator {
return &schedulerBootOp{
nodes: nodes,
cluster: cluster,
params: params,
files: common.NewFilesBuilder(nodes),
}
}
func (o *schedulerBootOp) Name() string {
return "kube-scheduler-bootstrap"
}
func (o *schedulerBootOp) NextCommand() cke.Commander {
switch o.step {
case 0:
o.step++
return common.ImagePullCommand(o.nodes, cke.HyperkubeImage)
case 1:
o.step++
return prepareSchedulerFilesCommand{o.cluster, o.files}
case 2:
o.step++
return o.files
case 3:
o.step++
return common.RunContainerCommand(o.nodes, op.KubeSchedulerContainerName, cke.HyperkubeImage,
common.WithParams(SchedulerParams()),
common.WithExtra(o.params))
default:
return nil
}
}
type prepareSchedulerFilesCommand struct {
cluster string
files *common.FilesBuilder
}
func (c prepareSchedulerFilesCommand) Run(ctx context.Context, inf cke.Infrastructure) error {
const kubeconfigPath = "/etc/kubernetes/scheduler/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{}.IssueForScheduler(ctx, inf)
if err != nil {
return nil, err
}
cfg := schedulerKubeconfig(c.cluster, ca, crt, key)
return clientcmd.Write(*cfg)
}
return c.files.AddFile(ctx, kubeconfigPath, g)
}
func (c prepareSchedulerFilesCommand) Command() cke.Command {
return cke.Command{
Name: "prepare-scheduler-files",
}
}
// SchedulerParams returns parameters for kube-scheduler.
func SchedulerParams() cke.ServiceParams {
args := []string{
"scheduler",
"--kubeconfig=/etc/kubernetes/scheduler/kubeconfig",
// for healthz service
"--tls-cert-file=" + op.K8sPKIPath("apiserver.crt"),
"--tls-private-key-file=" + op.K8sPKIPath("apiserver.key"),
"--port=0",
}
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,
},
},
}
}