Skip to content

Commit a1bf96f

Browse files
saintubeshenxin
andauthored
scheduler: allow to disable Controllers (#2452)
Signed-off-by: saintube <[email protected]> Co-authored-by: shenxin <[email protected]>
1 parent 376c3c3 commit a1bf96f

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

pkg/scheduler/frameworkext/controllers.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,37 @@ package frameworkext
1818

1919
import (
2020
"k8s.io/klog/v2"
21+
"k8s.io/kubernetes/pkg/scheduler/framework"
22+
)
2123

22-
"github.com/koordinator-sh/koordinator/pkg/descheduler/framework"
24+
var (
25+
ControllerPlugins = []string{"*"}
2326
)
2427

28+
func isControllerPluginEnabled(pluginName string) bool {
29+
hasStar := false
30+
for _, p := range ControllerPlugins {
31+
if p == pluginName {
32+
return true
33+
}
34+
if p == "-"+pluginName {
35+
return false
36+
}
37+
if p == "*" {
38+
hasStar = true
39+
}
40+
}
41+
return hasStar
42+
}
43+
44+
func getPluginControllerNames(pluginControllers map[string]Controller) []string {
45+
s := make([]string, 0, len(pluginControllers))
46+
for name := range pluginControllers {
47+
s = append(s, name)
48+
}
49+
return s
50+
}
51+
2552
type ControllerProvider interface {
2653
NewControllers() ([]Controller, error)
2754
}
@@ -67,8 +94,13 @@ func (cm *ControllersMap) RegisterControllers(plugin framework.Plugin) {
6794
}
6895

6996
func (cm *ControllersMap) Start() {
70-
for _, plugin := range cm.controllers {
71-
for _, controller := range plugin {
97+
for pluginName, pluginControllers := range cm.controllers {
98+
if !isControllerPluginEnabled(pluginName) {
99+
klog.V(0).Infof("controller plugin %v is disabled, controllers %v are skipped",
100+
pluginName, getPluginControllerNames(pluginControllers))
101+
continue
102+
}
103+
for _, controller := range pluginControllers {
72104
controller.Start()
73105
}
74106
}

pkg/scheduler/frameworkext/debug.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"strconv"
2323

2424
prettytable "github.com/jedib0t/go-pretty/v6/table"
25-
"github.com/spf13/pflag"
2625
corev1 "k8s.io/api/core/v1"
2726
"k8s.io/klog/v2"
2827
"k8s.io/kubernetes/pkg/scheduler/framework"
@@ -33,11 +32,6 @@ var (
3332
debugFilterFailure = false
3433
)
3534

36-
func AddFlags(fs *pflag.FlagSet) {
37-
fs.IntVarP(&debugTopNScores, "debug-scores", "s", debugTopNScores, "logging topN nodes score and scores for each plugin after running the score extension, disable if set to 0")
38-
fs.BoolVarP(&debugFilterFailure, "debug-filters", "f", debugFilterFailure, "logging filter failures")
39-
}
40-
4135
// DebugScoresSetter updates debugTopNScores to specified value
4236
func DebugScoresSetter(val string) (string, error) {
4337
topN, err := strconv.Atoi(val)

pkg/scheduler/frameworkext/framework_extender_factory.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strconv"
2323
"time"
2424

25+
"github.com/spf13/pflag"
2526
corev1 "k8s.io/api/core/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
@@ -42,6 +43,15 @@ import (
4243
koordschedulermetrics "github.com/koordinator-sh/koordinator/pkg/scheduler/metrics"
4344
)
4445

46+
func AddFlags(fs *pflag.FlagSet) {
47+
fs.IntVarP(&debugTopNScores, "debug-scores", "s", debugTopNScores, "logging topN nodes score and scores for each plugin after running the score extension, disable if set to 0")
48+
fs.BoolVarP(&debugFilterFailure, "debug-filters", "f", debugFilterFailure, "logging filter failures")
49+
fs.StringSliceVar(&ControllerPlugins, "controller-plugins", ControllerPlugins, "A list of Controller plugins to enable. "+
50+
"'-controller-plugins=*' enables all controller plugins. "+
51+
"'-controller-plugins=Reservation' means only the controller plugin 'Reservation' is enabled. "+
52+
"'-controller-plugins=*,-Reservation' means all controller plugins except the 'Reservation' plugin are enabled.")
53+
}
54+
4555
type extendedHandleOptions struct {
4656
servicesEngine *services.Engine
4757
koordinatorClientSet koordinatorclientset.Interface

0 commit comments

Comments
 (0)