Skip to content

Commit 83f550e

Browse files
Merge pull request volcano-sh#4661 from mvinchoo/mvinchoo/config
Feature: Option to disable default config fallback
2 parents e7c4ce9 + 2684359 commit 83f550e

4 files changed

Lines changed: 46 additions & 28 deletions

File tree

cmd/scheduler/app/options/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ type ServerOption struct {
9393
// not be counted in pod pvc resource request and node.Allocatable, because the spec.drivers of csinode resource
9494
// is always null, these provisioners usually are host path csi controllers like rancher.io/local-path and hostpath.csi.k8s.io.
9595
IgnoredCSIProvisioners []string
96+
97+
// DisableDefaultSchedulerConfig indicates if the scheduler should fallback to default
98+
// config if the current scheduler config is invalid
99+
DisableDefaultSchedulerConfig bool
96100
}
97101

98102
// DecryptFunc is custom function to parse ca file
@@ -151,6 +155,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
151155
fs.StringVar(&s.CacheDumpFileDir, "cache-dump-dir", "/tmp", "The target dir where the json file put at when dump cache info to json file")
152156
fs.Uint32Var(&s.NodeWorkerThreads, "node-worker-threads", defaultNodeWorkers, "The number of threads syncing node operations.")
153157
fs.StringSliceVar(&s.IgnoredCSIProvisioners, "ignored-provisioners", nil, "The provisioners that will be ignored during pod pvc request computation and preemption.")
158+
fs.BoolVar(&s.DisableDefaultSchedulerConfig, "disable-default-scheduler-config", false, "The flag indicates whether the scheduler should avoid using the default configuration if the provided scheduler configuration is invalid.")
154159
}
155160

156161
// CheckOptionOrDie check leader election flag when LeaderElection is enabled.

cmd/scheduler/app/options/options_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ func TestAddFlags(t *testing.T) {
7676
QPS: defaultQPS,
7777
Burst: defaultBurst,
7878
},
79-
PluginsDir: defaultPluginsDir,
80-
HealthzBindAddress: ":11251",
81-
MinNodesToFind: defaultMinNodesToFind,
82-
MinPercentageOfNodesToFind: defaultMinPercentageOfNodesToFind,
83-
PercentageOfNodesToFind: defaultPercentageOfNodesToFind,
84-
NodeWorkerThreads: defaultNodeWorkers,
85-
CacheDumpFileDir: "/tmp",
79+
PluginsDir: defaultPluginsDir,
80+
HealthzBindAddress: ":11251",
81+
MinNodesToFind: defaultMinNodesToFind,
82+
MinPercentageOfNodesToFind: defaultMinPercentageOfNodesToFind,
83+
PercentageOfNodesToFind: defaultPercentageOfNodesToFind,
84+
NodeWorkerThreads: defaultNodeWorkers,
85+
CacheDumpFileDir: "/tmp",
86+
DisableDefaultSchedulerConfig: false,
8687
}
8788
expectedFeatureGates := map[featuregate.Feature]bool{
8889
features.PodDisruptionBudgetsSupport: false,

pkg/scheduler/scheduler.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ type Scheduler struct {
5252
schedulePeriod time.Duration
5353
once sync.Once
5454

55-
mutex sync.Mutex
56-
actions []framework.Action
57-
plugins []conf.Tier
58-
configurations []conf.Configuration
59-
metricsConf map[string]string
60-
dumper schedcache.Dumper
55+
mutex sync.Mutex
56+
actions []framework.Action
57+
plugins []conf.Tier
58+
configurations []conf.Configuration
59+
metricsConf map[string]string
60+
dumper schedcache.Dumper
61+
disableDefaultConf bool
6162
}
6263

6364
// NewScheduler returns a Scheduler
@@ -74,11 +75,12 @@ func NewScheduler(config *rest.Config, opt *options.ServerOption) (*Scheduler, e
7475

7576
cache := schedcache.New(config, opt.SchedulerNames, opt.DefaultQueue, opt.NodeSelector, opt.NodeWorkerThreads, opt.IgnoredCSIProvisioners, opt.ResyncPeriod)
7677
scheduler := &Scheduler{
77-
schedulerConf: opt.SchedulerConf,
78-
fileWatcher: watcher,
79-
cache: cache,
80-
schedulePeriod: opt.SchedulePeriod,
81-
dumper: schedcache.Dumper{Cache: cache, RootDir: opt.CacheDumpFileDir},
78+
schedulerConf: opt.SchedulerConf,
79+
fileWatcher: watcher,
80+
cache: cache,
81+
schedulePeriod: opt.SchedulePeriod,
82+
dumper: schedcache.Dumper{Cache: cache, RootDir: opt.CacheDumpFileDir},
83+
disableDefaultConf: opt.DisableDefaultSchedulerConfig,
8284
}
8385

8486
return scheduler, nil
@@ -136,22 +138,30 @@ func (pc *Scheduler) loadSchedulerConf() {
136138
klog.V(4).Infof("Start loadSchedulerConf ...")
137139
defer func() {
138140
actions, plugins := pc.getSchedulerConf()
139-
klog.V(2).Infof("Successfully loaded Scheduler conf, actions: %v, plugins: %v", actions, plugins)
141+
klog.V(2).Infof("Finished loading scheduler config. Final state: actions=%v, plugins=%v", actions, plugins)
140142
}()
141143

144+
if pc.disableDefaultConf && len(pc.schedulerConf) == 0 {
145+
klog.Fatalf("No --scheduler-conf path provided and default configuration fallback is disabled")
146+
}
147+
142148
var err error
143-
pc.once.Do(func() {
144-
pc.actions, pc.plugins, pc.configurations, pc.metricsConf, err = UnmarshalSchedulerConf(DefaultSchedulerConf)
145-
if err != nil {
146-
klog.Errorf("unmarshal Scheduler config %s failed: %v", DefaultSchedulerConf, err)
147-
panic("invalid default configuration")
148-
}
149-
})
149+
if !pc.disableDefaultConf {
150+
pc.once.Do(func() {
151+
pc.actions, pc.plugins, pc.configurations, pc.metricsConf, err = UnmarshalSchedulerConf(DefaultSchedulerConf)
152+
if err != nil {
153+
klog.Fatalf("Invalid default configuration: unmarshal Scheduler config %s failed: %v", DefaultSchedulerConf, err)
154+
}
155+
})
156+
}
150157

151158
var config string
152159
if len(pc.schedulerConf) != 0 {
153160
confData, err := os.ReadFile(pc.schedulerConf)
154161
if err != nil {
162+
if pc.disableDefaultConf {
163+
klog.Fatalf("Failed to read scheduler config and default configuration fallback is disabled")
164+
}
155165
klog.Errorf("Failed to read the Scheduler config in '%s', using previous configuration: %v",
156166
pc.schedulerConf, err)
157167
return
@@ -161,6 +171,9 @@ func (pc *Scheduler) loadSchedulerConf() {
161171

162172
actions, plugins, configurations, metricsConf, err := UnmarshalSchedulerConf(config)
163173
if err != nil {
174+
if pc.disableDefaultConf {
175+
klog.Fatalf("Invalid scheduler configuration and default configuration fallback is disabled")
176+
}
164177
klog.Errorf("Scheduler config %s is invalid: %v", config, err)
165178
return
166179
}

pkg/scheduler/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"strings"
2929

3030
"gopkg.in/yaml.v2"
31-
"k8s.io/klog/v2"
3231

3332
"volcano.sh/volcano/pkg/scheduler/conf"
3433
"volcano.sh/volcano/pkg/scheduler/framework"
@@ -86,7 +85,7 @@ func UnmarshalSchedulerConf(confStr string) ([]framework.Action, []conf.Tier, []
8685
if action, found := framework.GetAction(strings.TrimSpace(actionName)); found {
8786
actions = append(actions, action)
8887
} else {
89-
klog.Errorf("Failed to find Action %s, ignore it", actionName)
88+
return nil, nil, nil, nil, fmt.Errorf("failed to find Action %s", actionName)
9089
}
9190
}
9291

0 commit comments

Comments
 (0)