Skip to content

Commit 35acd13

Browse files
YamasouAsanposhiho
andauthored
cleanup externalSchedulerEnable (#382)
* cleanup * update md doc * update doc * doc: add the second step to rebuild the scheduler --------- Co-authored-by: Kensei Nakada <[email protected]>
1 parent 34b8c1c commit 35acd13

File tree

10 files changed

+45
-207
lines changed

10 files changed

+45
-207
lines changed

simulator/cmd/simulator/simulator.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func startSimulator() error {
9494
return xerrors.Errorf("kubeapi-server is not ready: %w", err)
9595
}
9696

97-
dic, err := di.NewDIContainer(client, dynamicClient, restMapper, etcdclient, restCfg, cfg.InitialSchedulerCfg, cfg.ExternalImportEnabled, cfg.ResourceSyncEnabled, importClusterResourceClient, importClusterDynamicClient, cfg.ExternalSchedulerEnabled, cfg.Port, syncer.Options{})
97+
dic, err := di.NewDIContainer(client, dynamicClient, restMapper, etcdclient, restCfg, cfg.InitialSchedulerCfg, cfg.ExternalImportEnabled, cfg.ResourceSyncEnabled, importClusterResourceClient, importClusterDynamicClient, cfg.Port, syncer.Options{})
9898
if err != nil {
9999
return xerrors.Errorf("create di container: %w", err)
100100
}
@@ -110,9 +110,7 @@ func startSimulator() error {
110110
}
111111
}
112112

113-
if !cfg.ExternalSchedulerEnabled {
114-
dic.SchedulerService().SetSchedulerConfig(cfg.InitialSchedulerCfg)
115-
}
113+
dic.SchedulerService().SetSchedulerConfig(cfg.InitialSchedulerCfg)
116114

117115
if cfg.ResourceSyncEnabled {
118116
// Start the resource syncer to sync resources from the target cluster.

simulator/config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,3 @@ externalImportEnabled: false
4747
# You cannot make both externalImportEnabled and resourceSyncEnabled true because those features would be conflicted.
4848
# Note, this is still a beta feature.
4949
resourceSyncEnabled: false
50-
51-
# This variable indicates whether an external scheduler
52-
# is used.
53-
externalSchedulerEnabled: false

simulator/config/config.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ type Config struct {
4343
// This field should be set when ExternalImportEnabled == true or ResourceSyncEnabled == true.
4444
ExternalKubeClientCfg *rest.Config
4545
InitialSchedulerCfg *configv1.KubeSchedulerConfiguration
46-
// ExternalSchedulerEnabled indicates whether an external scheduler is enabled.
47-
ExternalSchedulerEnabled bool
4846
}
4947

5048
const (
@@ -99,18 +97,15 @@ func NewConfig() (*Config, error) {
9997
return nil, xerrors.Errorf("get SchedulerCfg: %w", err)
10098
}
10199

102-
externalSchedEnabled := getExternalSchedulerEnabled()
103-
104100
return &Config{
105-
Port: port,
106-
KubeAPIServerURL: apiurl,
107-
EtcdURL: etcdurl,
108-
CorsAllowedOriginList: corsAllowedOriginList,
109-
InitialSchedulerCfg: initialschedulerCfg,
110-
ExternalImportEnabled: externalimportenabled,
111-
ExternalKubeClientCfg: externalKubeClientCfg,
112-
ExternalSchedulerEnabled: externalSchedEnabled,
113-
ResourceSyncEnabled: resourceSyncEnabled,
101+
Port: port,
102+
KubeAPIServerURL: apiurl,
103+
EtcdURL: etcdurl,
104+
CorsAllowedOriginList: corsAllowedOriginList,
105+
InitialSchedulerCfg: initialschedulerCfg,
106+
ExternalImportEnabled: externalimportenabled,
107+
ExternalKubeClientCfg: externalKubeClientCfg,
108+
ResourceSyncEnabled: resourceSyncEnabled,
114109
}, nil
115110
}
116111

@@ -163,17 +158,6 @@ func getKubeAPIServerURL() (string, error) {
163158
return url, nil
164159
}
165160

166-
// getExternalSchedulerEnabled gets ExternalSchedulerEnabled from environment variable first,
167-
// if empty from the config file.
168-
func getExternalSchedulerEnabled() bool {
169-
e := os.Getenv("EXTERNAL_SCHEDULER_ENABLED")
170-
b, err := strconv.ParseBool(e)
171-
if e == "" || err != nil {
172-
b = configYaml.ExternalSchedulerEnabled
173-
}
174-
return b
175-
}
176-
177161
// getEtcdURL gets EtcdURL from environment variable first,
178162
// if empty from the config file.
179163
func getEtcdURL() (string, error) {

simulator/docs/custom-plugin.md

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
## Debuggable scheduler
22

3-
The "debuggable scheduler" is the core concept of the simulator.
4-
5-
### What's the "debuggable scheduler"?
6-
7-
The debuggable scheduler is the scheduler that schedules Pods like other schedulers,
8-
but it exposes the scheduling results from each scheduling plugin on Pod annotation.
3+
The "debuggable scheduler" is the core component of the simulator,
4+
which is responsible for scheduling Pods like the normal scheduler, but also recording all the scheduling details to the Pod annotations.
95

106
```yaml
117
kind: Pod
@@ -35,60 +31,45 @@ metadata:
3531
scheduler-simulator/selected-node: node-282x7
3632
```
3733
38-
The simulator runs the debuggable scheduler built from the upstream scheduler by default,
39-
that's why we can see the scheduling results like the above in the simulator.
40-
41-
## Build a debuggable scheduler from your scheduler
42-
43-
You can use the [`debuggablescheduler` package](../pkg/debuggablescheduler) to transform your scheduler into a debuggable scheduler.
34+
The simulator works with the debuggable scheduler built from the upstream scheduler by default,
35+
and the web UI just visualizes those scheduling details on the annotations.
4436
45-
The debuggable scheduler could work anywhere, in the simulator or even in your cluster.
37+
## Integrate your plugins to the simulator
4638
47-
### Change your scheduler
48-
49-
Here, we assume you're registering your custom plugins in your scheduler like this:
50-
51-
```go
52-
// your scheduler's main package
53-
func main() {
54-
command := app.NewSchedulerCommand(
55-
app.WithPlugin(yourcustomplugin.Name, yourcustomplugin.New),
56-
)
57-
58-
code := cli.Run(command)
59-
os.Exit(code)
60-
}
61-
```
39+
You can integrate your plugins to the simulator, that is, to the debuggable scheduler working within the simulator, by following these steps:
6240
63-
Then, you need to replace few lines to use the [`debuggablescheduler` package](../pkg/debuggablescheduler).
41+
1. Register your plugins [here](../cmd/scheduler/scheduler.go#L17) in a very similar way you do with the normal scheduler.
6442
6543
```go
66-
func main() {
67-
command, cancelFn, err := debuggablescheduler.NewSchedulerCommand(
44+
command, cancelFn, err := debuggablescheduler.NewSchedulerCommand(
6845
debuggablescheduler.WithPlugin(yourcustomplugin.Name, yourcustomplugin.New),
6946
debuggablescheduler.WithPluginExtenders(noderesources.Name, extender.New), // [optional] see plugin-extender.md about PluginExtender.
7047
)
71-
if err != nil {
72-
klog.Info(fmt.Sprintf("failed to build the scheduler command: %+v", err))
73-
os.Exit(1)
74-
}
75-
code := cli.Run(command)
76-
cancelFn()
77-
os.Exit(code)
78-
}
7948
```
8049

81-
As you see, `debuggablescheduler.NewSchedulerCommand` has much similar interface as the `app.NewSchedulerCommand`.
82-
You can register your plugins by `debuggablescheduler.WithPlugin` option.
50+
2. Rebuild the scheduler and restart.
51+
52+
```sh
53+
make docker_build docker_up_local
54+
```
8355

8456
### The plugin extender
8557

86-
We have the plugin extender feature to expand the debuggable scheduler more.
87-
See [plugin-extender.md](./plugin-extender.md) to know more about it.
58+
We have the plugin extender feature to provide more debuggability from the debuggable scheduler.
59+
See [plugin-extender.md](./plugin-extender.md).
8860

89-
### The example debuggable scheduler
61+
### Use the debuggable scheduler in your dev cluster
62+
63+
The debuggable scheduler can work outside the simulator, that is, in your clusters too.
64+
which allows you to have the same debuggability with your custom scheduler in real clusters.
9065

91-
We have the sample implementation in [./sample/debuggable-scheduler](./sample/debuggable-scheduler).
66+
It's just a single binary that doesn't contain anything but the debuggability features that we described so far.
67+
68+
> [!NOTE]
69+
> We do not recommend using it in the production cluster because the debuggable scheduler contains the overhead.
70+
> Also, you may want to pay attention to the fact that the annotations would be visible to all cluster users,
71+
> which could leak the hints of other tenants to cluster users.
72+
73+
### The example debuggable scheduler
9274

93-
You can try to run it in the simulator via [external scheduler](./external-scheduler.md) feature.
94-
See [external-scheduler.md#the-example-external-scheduler](./external-scheduler.md#the-example-external-scheduler).
75+
We have the sample to show how to implement the debuggable scheduler in [./sample/debuggable-scheduler](./sample/debuggable-scheduler).

simulator/docs/external-scheduler.md

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
## External scheduler
2-
3-
The external scheduler is the feature of the simulator
4-
to allow you to run any of your scheduler in the simulator instead of the default one.
5-
6-
Before diving into the description, you need to know [debuggable scheduler](./debuggable-scheduler.md).
7-
8-
### connect your scheduler to the simulator
9-
10-
Let's connect your scheduler to the simulator.
11-
12-
First, you need to set `externalSchedulerEnabled: true` on [the simulator config](../config.yaml)
13-
so that the scheduler, running in the simulator by default, won't get started.
14-
15-
Next, you need to connect your scheduler into the simulator's kube-apiserver via KubeSchedulerConfig:
16-
17-
```yaml
18-
kind: KubeSchedulerConfiguration
19-
apiVersion: kubescheduler.config.k8s.io/v1
20-
clientConnection:
21-
kubeconfig: ./path/to/kubeconfig.yaml
22-
```
23-
24-
You can use this [kubeconfig.yaml](./kubeconfig.yaml) to communicate with the simulator's kube-apiserver.
25-
26-
### The example external scheduler
27-
28-
You can see how the external scheduler can be set up
29-
with the sample debuggable scheduler implementation in [./sample/debuggable-scheduler](./sample/debuggable-scheduler).
30-
31-
prerequisite:
32-
1. set `externalSchedulerEnabled: true` on [the simulator config](../config.yaml)
33-
2. run the simulator
34-
35-
```shell
36-
cd sample/debuggable-scheduler
37-
go run main.go --config scheduler.yaml
38-
```
39-
40-
You'll see the simulator is working with the external scheduler.
1+
> [!CAUTION]
2+
We previously had a feature called the external scheduler, but we removed it in favor of [debuggable scheduler](../debuggable-scheduler.md).
3+
To maintain compatibility, the externalSchedulerEnabled setting remains for now though, will be removed in the near future.
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
## Integrate your scheduler
22

3-
There are several ways to integrate your scheduler into the simulator.
3+
You can integrate your scheduler into the simulator.
44

5-
Basically you have two options on the table:
6-
- Integrate your scheduler plugins into the scheduler running in the simulator
7-
- Check out [custom-plugin.md](./custom-plugin.md)
8-
- Disable the scheduler running in the simulator and use your scheduler instead
9-
- We call this feature "external scheduler"
10-
- Check out [external-scheduler.md](./external-scheduler.md)
5+
To add your custom scheduler plugins, see [debuggable-scheduler.md](./debuggable-scheduler.md#integrate-your-plugins-to-the-simulator).
116

127
Also, if you just want to use your `KubeSchedulerConfig` while using default plugins,
138
you don't need to follow this page. Check out [simulator-server-config.md](./simulator-server-config.md) instead.

simulator/docs/simulator-server-config.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,4 @@ externalImportEnabled: false
5151
# You cannot make both externalImportEnabled and resourceSyncEnabled true because those features would be conflicted.
5252
# Note, this is still a beta feature.
5353
resourceSyncEnabled: false
54-
55-
# This variable indicates whether an external scheduler
56-
# is used.
57-
externalSchedulerEnabled: false
5854
```

simulator/scheduler/scheduler.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ type Service struct {
2828
// function to shutdown scheduler.
2929
shutdownfn func()
3030

31-
// disabled represents if this Service is disabled.
32-
// If externalSchedulerEnabled, it'll be true
33-
// because we don't need to start scheduler, and we cannot change an external scheduler's config in that case.
34-
disabled bool
35-
3631
clientset clientset.Interface
3732
restclientCfg *restclient.Config
3833
initialSchedulerCfg *configv1.KubeSchedulerConfiguration
@@ -52,11 +47,7 @@ type ExtenderService interface {
5247
var ErrServiceDisabled = errors.New("scheduler service is disabled")
5348

5449
// NewSchedulerService starts scheduler and return *Service.
55-
func NewSchedulerService(client clientset.Interface, restclientCfg *restclient.Config, initialSchedulerCfg *configv1.KubeSchedulerConfiguration, externalSchedulerEnabled bool, simulatorPort int) *Service {
56-
if externalSchedulerEnabled {
57-
return &Service{disabled: true}
58-
}
59-
50+
func NewSchedulerService(client clientset.Interface, restclientCfg *restclient.Config, initialSchedulerCfg *configv1.KubeSchedulerConfiguration, simulatorPort int) *Service {
6051
// sharedStore has some resultstores which are referenced by Registry of Plugins and Extenders.
6152
sharedStore := storereflector.New()
6253

@@ -131,10 +122,6 @@ func (s *Service) ShutdownScheduler() {
131122
}
132123

133124
func (s *Service) GetSchedulerConfig() (*configv1.KubeSchedulerConfiguration, error) {
134-
if s.disabled {
135-
return nil, xerrors.Errorf("an external scheduler is enabled: %w", ErrServiceDisabled)
136-
}
137-
138125
return s.currentSchedulerCfg, nil
139126
}
140127

simulator/server/di/di.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ func NewDIContainer(
4444
resourceSyncEnabled bool,
4545
externalClient clientset.Interface,
4646
externalDynamicClient dynamic.Interface,
47-
externalSchedulerEnabled bool,
4847
simulatorPort int,
4948
syncerOptions syncer.Options,
5049
) (*Container, error) {
5150
c := &Container{}
5251

5352
// initializes each service
54-
c.schedulerService = scheduler.NewSchedulerService(client, restclientCfg, initialSchedulerCfg, externalSchedulerEnabled, simulatorPort)
53+
c.schedulerService = scheduler.NewSchedulerService(client, restclientCfg, initialSchedulerCfg, simulatorPort)
5554
var err error
5655
c.resetService, err = reset.NewResetService(etcdclient, client, c.schedulerService)
5756
if err != nil {

0 commit comments

Comments
 (0)