forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_kube_scheduler.go
66 lines (58 loc) · 2.07 KB
/
start_kube_scheduler.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
package start
import (
"fmt"
"time"
"github.com/golang/glog"
schedulerapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
)
func computeSchedulerArgs(kubeconfigFile, schedulerConfigFile string, qps float32, burst int, schedulerArgs map[string][]string) []string {
cmdLineArgs := map[string][]string{}
// deep-copy the input args to avoid mutation conflict.
for k, v := range schedulerArgs {
cmdLineArgs[k] = append([]string{}, v...)
}
if len(cmdLineArgs["kubeconfig"]) == 0 {
cmdLineArgs["kubeconfig"] = []string{kubeconfigFile}
}
if len(cmdLineArgs["policy-config-file"]) == 0 {
cmdLineArgs["policy-config-file"] = []string{schedulerConfigFile}
}
if _, ok := cmdLineArgs["kube-api-content-type"]; !ok {
cmdLineArgs["kube-api-content-type"] = []string{"application/vnd.kubernetes.protobuf"}
}
if _, ok := cmdLineArgs["kube-api-qps"]; !ok {
cmdLineArgs["kube-api-qps"] = []string{fmt.Sprintf("%v", qps)}
}
if _, ok := cmdLineArgs["kube-api-burst"]; !ok {
cmdLineArgs["kube-api-burst"] = []string{fmt.Sprintf("%v", burst)}
}
if _, ok := cmdLineArgs["leader-elect"]; !ok {
cmdLineArgs["leader-elect"] = []string{"true"}
}
if len(cmdLineArgs["leader-elect-resource-lock"]) == 0 {
cmdLineArgs["leader-elect-resource-lock"] = []string{"configmaps"}
}
// disable serving http since we didn't used to expose it
if len(cmdLineArgs["port"]) == 0 {
cmdLineArgs["port"] = []string{"-1"}
}
args := []string{}
for key, value := range cmdLineArgs {
for _, token := range value {
args = append(args, fmt.Sprintf("--%s=%v", key, token))
}
}
return args
}
func runEmbeddedScheduler(kubeconfigFile, schedulerConfigFile string, qps float32, burst int, cmdLineArgs map[string][]string) {
cmd := schedulerapp.NewSchedulerCommand()
args := computeSchedulerArgs(kubeconfigFile, schedulerConfigFile, qps, burst, cmdLineArgs)
if err := cmd.ParseFlags(args); err != nil {
glog.Fatal(err)
}
glog.Infof("`kube-scheduler %v`", args)
cmd.Run(cmd, nil)
glog.Fatalf("`kube-scheduler %v` exited", args)
time.Sleep(10 * time.Second)
}