forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart_scheduler.go
53 lines (46 loc) · 1.72 KB
/
start_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
package start
import (
"github.com/golang/glog"
kerrors "k8s.io/apimachinery/pkg/util/errors"
schedulerapp "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app"
scheduleroptions "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app/options"
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
)
func newScheduler(kubeconfigFile, schedulerConfigFile string, cmdLineArgs map[string][]string) (*scheduleroptions.SchedulerServer, error) {
if cmdLineArgs == nil {
cmdLineArgs = map[string][]string{}
}
if len(cmdLineArgs["kubeconfig"]) == 0 {
cmdLineArgs["kubeconfig"] = []string{kubeconfigFile}
}
if len(cmdLineArgs["policy-config-file"]) == 0 {
cmdLineArgs["policy-config-file"] = []string{schedulerConfigFile}
}
// disable serving http since we didn't used to expose it
if len(cmdLineArgs["port"]) == 0 {
cmdLineArgs["port"] = []string{"-1"}
}
// resolve arguments
schedulerServer := scheduleroptions.NewSchedulerServer()
if err := cmdflags.Resolve(cmdLineArgs, schedulerServer.AddFlags); len(err) > 0 {
return nil, kerrors.NewAggregate(err)
}
return schedulerServer, nil
}
func runEmbeddedScheduler(kubeconfigFile, schedulerConfigFile string, cmdLineArgs map[string][]string) {
for {
// TODO we need a real identity for this. Right now it's just using the loopback connection like it used to.
scheduler, err := newScheduler(kubeconfigFile, schedulerConfigFile, cmdLineArgs)
if err != nil {
glog.Error(err)
continue
}
// this does a second leader election, but doing the second leader election will allow us to move out process in
// 3.8 if we so choose.
if err := schedulerapp.Run(scheduler); err != nil {
glog.Error(err)
continue
}
}
}