Skip to content

Commit df4f033

Browse files
authored
Merge pull request kubernetes#77501 from JieJhih/scheduling/plugin
add scheduling framework configuration
2 parents a67f128 + 0734d1d commit df4f033

File tree

23 files changed

+1001
-47
lines changed

23 files changed

+1001
-47
lines changed

cmd/kube-scheduler/app/options/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ go_test(
7070
"//cmd/kube-scheduler/app/config:go_default_library",
7171
"//pkg/scheduler/apis/config:go_default_library",
7272
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
73+
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
7374
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
7475
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
7576
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",

cmd/kube-scheduler/app/options/options_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"time"
3030

3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+
"k8s.io/apimachinery/pkg/runtime"
3233
"k8s.io/apimachinery/pkg/util/diff"
3334
apiserveroptions "k8s.io/apiserver/pkg/server/options"
3435
componentbaseconfig "k8s.io/component-base/config"
@@ -146,6 +147,31 @@ users:
146147
t.Fatal(err)
147148
}
148149

150+
// plugin config
151+
pluginconfigFile := filepath.Join(tmpDir, "plugin.yaml")
152+
if err := ioutil.WriteFile(pluginconfigFile, []byte(fmt.Sprintf(`
153+
apiVersion: kubescheduler.config.k8s.io/v1alpha1
154+
kind: KubeSchedulerConfiguration
155+
clientConnection:
156+
kubeconfig: "%s"
157+
plugins:
158+
reserve:
159+
enabled:
160+
- name: foo
161+
- name: bar
162+
disabled:
163+
- name: baz
164+
preBind:
165+
enabled:
166+
- name: foo
167+
disabled:
168+
- name: baz
169+
pluginConfig:
170+
- name: foo
171+
`, configKubeconfig)), os.FileMode(0600)); err != nil {
172+
t.Fatal(err)
173+
}
174+
149175
// Insulate this test from picking up in-cluster config when run inside a pod
150176
// We can't assume we have permissions to write to /var/run/secrets/... from a unit test to mock in-cluster config for testing
151177
originalHost := os.Getenv("KUBERNETES_SERVICE_HOST")
@@ -224,6 +250,7 @@ users:
224250
ContentType: "application/vnd.kubernetes.protobuf",
225251
},
226252
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
253+
Plugins: nil,
227254
},
228255
},
229256
{
@@ -334,6 +361,73 @@ users:
334361
},
335362
expectedUsername: "none, http",
336363
},
364+
{
365+
name: "plugin config",
366+
options: &Options{
367+
ConfigFile: pluginconfigFile,
368+
},
369+
expectedUsername: "config",
370+
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
371+
SchedulerName: "default-scheduler",
372+
AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource},
373+
HardPodAffinitySymmetricWeight: 1,
374+
HealthzBindAddress: "0.0.0.0:10251",
375+
MetricsBindAddress: "0.0.0.0:10251",
376+
LeaderElection: kubeschedulerconfig.KubeSchedulerLeaderElectionConfiguration{
377+
LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
378+
LeaderElect: true,
379+
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
380+
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
381+
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
382+
ResourceLock: "endpoints",
383+
},
384+
LockObjectNamespace: "kube-system",
385+
LockObjectName: "kube-scheduler",
386+
},
387+
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
388+
Kubeconfig: configKubeconfig,
389+
QPS: 50,
390+
Burst: 100,
391+
ContentType: "application/vnd.kubernetes.protobuf",
392+
},
393+
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
394+
Plugins: &kubeschedulerconfig.Plugins{
395+
Reserve: &kubeschedulerconfig.PluginSet{
396+
Enabled: []kubeschedulerconfig.Plugin{
397+
{
398+
Name: "foo",
399+
},
400+
{
401+
Name: "bar",
402+
},
403+
},
404+
Disabled: []kubeschedulerconfig.Plugin{
405+
{
406+
Name: "baz",
407+
},
408+
},
409+
},
410+
PreBind: &kubeschedulerconfig.PluginSet{
411+
Enabled: []kubeschedulerconfig.Plugin{
412+
{
413+
Name: "foo",
414+
},
415+
},
416+
Disabled: []kubeschedulerconfig.Plugin{
417+
{
418+
Name: "baz",
419+
},
420+
},
421+
},
422+
},
423+
PluginConfig: []kubeschedulerconfig.PluginConfig{
424+
{
425+
Name: "foo",
426+
Args: runtime.Unknown{},
427+
},
428+
},
429+
},
430+
},
337431
{
338432
name: "no config",
339433
options: &Options{},

cmd/kube-scheduler/app/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
176176
cc.ComponentConfig.AlgorithmSource,
177177
stopCh,
178178
framework.NewRegistry(),
179+
cc.ComponentConfig.Plugins,
180+
cc.ComponentConfig.PluginConfig,
179181
scheduler.WithName(cc.ComponentConfig.SchedulerName),
180182
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
181183
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),

pkg/scheduler/apis/config/types.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package config
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
2122
componentbaseconfig "k8s.io/component-base/config"
2223
)
2324

@@ -86,6 +87,17 @@ type KubeSchedulerConfiguration struct {
8687
// Value must be non-negative integer. The value zero indicates no waiting.
8788
// If this value is nil, the default value will be used.
8889
BindTimeoutSeconds *int64
90+
91+
// Plugins specify the set of plugins that should be enabled or disabled. Enabled plugins are the
92+
// ones that should be enabled in addition to the default plugins. Disabled plugins are any of the
93+
// default plugins that should be disabled.
94+
// When no enabled or disabled plugin is specified for an extension point, default plugins for
95+
// that extension point will be used if there is any.
96+
Plugins *Plugins
97+
98+
// PluginConfig is an optional set of custom plugin arguments for each plugin.
99+
// Omitting config args for a plugin is equivalent to using the default config for that plugin.
100+
PluginConfig []PluginConfig
89101
}
90102

91103
// SchedulerAlgorithmSource is the source of a scheduler algorithm. One source
@@ -131,3 +143,76 @@ type KubeSchedulerLeaderElectionConfiguration struct {
131143
// LockObjectName defines the lock object name
132144
LockObjectName string
133145
}
146+
147+
// Plugins include multiple extension points. When specified, the list of plugins for
148+
// a particular extension point are the only ones enabled. If an extension point is
149+
// omitted from the config, then the default set of plugins is used for that extension point.
150+
// Enabled plugins are called in the order specified here, after default plugins. If they need to
151+
// be invoked before default plugins, default plugins must be disabled and re-enabled here in desired order.
152+
type Plugins struct {
153+
// QueueSort is a list of plugins that should be invoked when sorting pods in the scheduling queue.
154+
QueueSort *PluginSet
155+
156+
// PreFilter is a list of plugins that should be invoked at "PreFilter" extension point of the scheduling framework.
157+
PreFilter *PluginSet
158+
159+
// Filter is a list of plugins that should be invoked when filtering out nodes that cannot run the Pod.
160+
Filter *PluginSet
161+
162+
// PostFilter is a list of plugins that are invoked after filtering out infeasible nodes.
163+
PostFilter *PluginSet
164+
165+
// Score is a list of plugins that should be invoked when ranking nodes that have passed the filtering phase.
166+
Score *PluginSet
167+
168+
// NormalizeScore is a list of plugins that should be invoked after the scoring phase to normalize scores.
169+
NormalizeScore *PluginSet
170+
171+
// Reserve is a list of plugins invoked when reserving a node to run the pod.
172+
Reserve *PluginSet
173+
174+
// Permit is a list of plugins that control binding of a Pod. These plugins can prevent or delay binding of a Pod.
175+
Permit *PluginSet
176+
177+
// PreBind is a list of plugins that should be invoked before a pod is bound.
178+
PreBind *PluginSet
179+
180+
// Bind is a list of plugins that should be invoked at "Bind" extension point of the scheduling framework.
181+
// The scheduler call these plugins in order. Scheduler skips the rest of these plugins as soon as one returns success.
182+
Bind *PluginSet
183+
184+
// PostBind is a list of plugins that should be invoked after a pod is successfully bound.
185+
PostBind *PluginSet
186+
187+
// Unreserve is a list of plugins invoked when a pod that was previously reserved is rejected in a later phase.
188+
Unreserve *PluginSet
189+
}
190+
191+
// PluginSet specifies enabled and disabled plugins for an extension point.
192+
// If an array is empty, missing, or nil, default plugins at that extension point will be used.
193+
type PluginSet struct {
194+
// Enabled specifies plugins that should be enabled in addition to default plugins.
195+
// These are called after default plugins and in the same order specified here.
196+
Enabled []Plugin
197+
// Disabled specifies default plugins that should be disabled.
198+
// When all default plugins need to be disabled, an array containing only one "*" should be provided.
199+
Disabled []Plugin
200+
}
201+
202+
// Plugin specifies a plugin name and its weight when applicable. Weight is used only for Score plugins.
203+
type Plugin struct {
204+
// Name defines the name of plugin
205+
Name string
206+
// Weight defines the weight of plugin, only used for Score plugins.
207+
Weight int32
208+
}
209+
210+
// PluginConfig specifies arguments that should be passed to a plugin at the time of initialization.
211+
// A plugin that is invoked at multiple extension points is initialized once. Args can have arbitrary structure.
212+
// It is up to the plugin to process these Args.
213+
type PluginConfig struct {
214+
// Name defines the name of plugin being configured
215+
Name string
216+
// Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure.
217+
Args runtime.Unknown
218+
}

0 commit comments

Comments
 (0)