Skip to content

Commit 5f0c7b2

Browse files
Merge pull request #16015 from deads2k/controller-07-move-scheduler
Automatic merge from submit-queue run scheduler by wiring up to a command Wires the scheduler into the controllers by running the command with flags. This prevents nearly all of our rebase pain in the wiring area with scheduler.
2 parents 665899f + 3783e1b commit 5f0c7b2

File tree

6 files changed

+84
-112
lines changed

6 files changed

+84
-112
lines changed

pkg/cmd/server/kubernetes/master/controller/config.go

-47
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
package controller
22

33
import (
4-
"fmt"
5-
"io/ioutil"
6-
"os"
7-
8-
"k8s.io/apimachinery/pkg/runtime"
9-
kerrors "k8s.io/apimachinery/pkg/util/errors"
104
kubecontroller "k8s.io/kubernetes/cmd/kube-controller-manager/app"
11-
scheduleroptions "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app/options"
12-
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
13-
latestschedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api/latest"
145

156
configapi "github.com/openshift/origin/pkg/cmd/server/api"
16-
cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
177
"github.com/openshift/origin/pkg/cmd/util/variable"
188
"k8s.io/kubernetes/pkg/volume"
199
)
@@ -22,9 +12,6 @@ import (
2212
// launch the set of kube (not openshift) controllers.
2313
type KubeControllerConfig struct {
2414
HorizontalPodAutoscalerControllerConfig HorizontalPodAutoscalerControllerConfig
25-
26-
// TODO the scheduler should move out into its own logical component
27-
SchedulerControllerConfig SchedulerControllerConfig
2815
}
2916

3017
// GetControllerInitializers return the controller initializer functions for kube controllers
@@ -36,48 +23,14 @@ func (c KubeControllerConfig) GetControllerInitializers() (map[string]kubecontro
3623
// in openshift-infra, and pass it a scale client that knows how to scale DCs
3724
ret["horizontalpodautoscaling"] = c.HorizontalPodAutoscalerControllerConfig.RunController
3825

39-
// FIXME: Move this under openshift controller intialization once we figure out
40-
// deployment (options).
41-
ret["openshift.io/scheduler"] = c.SchedulerControllerConfig.RunController
42-
4326
return ret, nil
4427
}
4528

4629
// BuildKubeControllerConfig builds the struct to create the controller initializers. Eventually we want this to be fully
4730
// stock kube with no modification.
4831
func BuildKubeControllerConfig(options configapi.MasterConfig) (*KubeControllerConfig, error) {
49-
var err error
5032
ret := &KubeControllerConfig{}
5133

52-
kubeExternal, _, err := configapi.GetExternalKubeClient(options.MasterClients.OpenShiftLoopbackKubeConfig, options.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
53-
if err != nil {
54-
return nil, err
55-
}
56-
57-
var schedulerPolicy *schedulerapi.Policy
58-
if _, err := os.Stat(options.KubernetesMasterConfig.SchedulerConfigFile); err == nil {
59-
schedulerPolicy = &schedulerapi.Policy{}
60-
configData, err := ioutil.ReadFile(options.KubernetesMasterConfig.SchedulerConfigFile)
61-
if err != nil {
62-
return nil, fmt.Errorf("unable to read scheduler config: %v", err)
63-
}
64-
if err := runtime.DecodeInto(latestschedulerapi.Codec, configData, schedulerPolicy); err != nil {
65-
return nil, fmt.Errorf("invalid scheduler configuration: %v", err)
66-
}
67-
}
68-
// resolve extended arguments
69-
// TODO: this should be done in config validation (along with the above) so we can provide
70-
// proper errors
71-
schedulerserver := scheduleroptions.NewSchedulerServer()
72-
schedulerserver.PolicyConfigFile = options.KubernetesMasterConfig.SchedulerConfigFile
73-
if err := cmdflags.Resolve(options.KubernetesMasterConfig.SchedulerArguments, schedulerserver.AddFlags); len(err) > 0 {
74-
return nil, kerrors.NewAggregate(err)
75-
}
76-
ret.SchedulerControllerConfig = SchedulerControllerConfig{
77-
PrivilegedClient: kubeExternal,
78-
SchedulerServer: schedulerserver,
79-
}
80-
8134
imageTemplate := variable.NewDefaultImageTemplate()
8235
imageTemplate.Format = options.ImageConfig.Format
8336
imageTemplate.Latest = options.ImageConfig.Latest

pkg/cmd/server/kubernetes/master/controller/core.go

-47
This file was deleted.

pkg/cmd/server/start/start_master.go

+3
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ func (m *Master) Start() error {
472472
go func() {
473473
controllerPlug.WaitForStart()
474474

475+
// continuously run the scheduler while we have the primary lease
476+
go runEmbeddedScheduler(m.config.MasterClients.OpenShiftLoopbackKubeConfig, m.config.KubernetesMasterConfig.SchedulerConfigFile, m.config.KubernetesMasterConfig.SchedulerArguments)
477+
475478
controllerContext, err := getControllerContext(*m.config, kubeControllerManagerConfig, cloudProvider, informers, utilwait.NeverStop)
476479
if err != nil {
477480
glog.Fatal(err)
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package start
2+
3+
import (
4+
"github.com/golang/glog"
5+
6+
kerrors "k8s.io/apimachinery/pkg/util/errors"
7+
schedulerapp "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app"
8+
scheduleroptions "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app/options"
9+
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
10+
11+
cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
12+
)
13+
14+
func newScheduler(kubeconfigFile, schedulerConfigFile string, cmdLineArgs map[string][]string) (*scheduleroptions.SchedulerServer, error) {
15+
if cmdLineArgs == nil {
16+
cmdLineArgs = map[string][]string{}
17+
}
18+
if len(cmdLineArgs["kubeconfig"]) == 0 {
19+
cmdLineArgs["kubeconfig"] = []string{kubeconfigFile}
20+
}
21+
if len(cmdLineArgs["policy-config-file"]) == 0 {
22+
cmdLineArgs["policy-config-file"] = []string{schedulerConfigFile}
23+
}
24+
// disable serving http since we didn't used to expose it
25+
if len(cmdLineArgs["port"]) == 0 {
26+
cmdLineArgs["port"] = []string{"-1"}
27+
}
28+
29+
// resolve arguments
30+
schedulerServer := scheduleroptions.NewSchedulerServer()
31+
if err := cmdflags.Resolve(cmdLineArgs, schedulerServer.AddFlags); len(err) > 0 {
32+
return nil, kerrors.NewAggregate(err)
33+
}
34+
35+
return schedulerServer, nil
36+
}
37+
38+
func runEmbeddedScheduler(kubeconfigFile, schedulerConfigFile string, cmdLineArgs map[string][]string) {
39+
for {
40+
// TODO we need a real identity for this. Right now it's just using the loopback connection like it used to.
41+
scheduler, err := newScheduler(kubeconfigFile, schedulerConfigFile, cmdLineArgs)
42+
if err != nil {
43+
glog.Error(err)
44+
continue
45+
}
46+
// this does a second leader election, but doing the second leader election will allow us to move out process in
47+
// 3.8 if we so choose.
48+
if err := schedulerapp.Run(scheduler); err != nil {
49+
glog.Error(err)
50+
continue
51+
}
52+
}
53+
}

vendor/k8s.io/kubernetes/plugin/cmd/kube-scheduler/app/BUILD

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/k8s.io/kubernetes/plugin/cmd/kube-scheduler/app/server.go

+27-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)