Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 4ec1cce

Browse files
authored
Merge pull request #807 from k82cn/automated-cherry-pick-of-#725-upstream-release-0.4
Automated cherry pick of #725: add options to enable the feature of PriorityClass
2 parents ba47bbb + 03a1fa9 commit 4ec1cce

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

cmd/kube-batch/app/options/options.go

+9
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ type ServerOption struct {
4242
DefaultQueue string
4343
PrintVersion bool
4444
ListenAddress string
45+
EnablePriorityClass bool
4546
}
4647

48+
var ServerOpts *ServerOption
49+
4750
// NewServerOption creates a new CMServer with a default config.
4851
func NewServerOption() *ServerOption {
4952
s := ServerOption{}
@@ -65,6 +68,8 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
6568
fs.BoolVar(&s.PrintVersion, "version", false, "Show version and quit")
6669
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object")
6770
fs.StringVar(&s.ListenAddress, "listen-address", defaultListenAddress, "The address to listen on for HTTP requests.")
71+
fs.BoolVar(&s.EnablePriorityClass, "priority-class", true,
72+
"Enable PriorityClass to provide the capacity of preemption at pod group level; to disable it, set it false")
6873
}
6974

7075
func (s *ServerOption) CheckOptionOrDie() error {
@@ -74,3 +79,7 @@ func (s *ServerOption) CheckOptionOrDie() error {
7479

7580
return nil
7681
}
82+
83+
func (s *ServerOption) RegisterOptions() {
84+
ServerOpts = s
85+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestAddFlags(t *testing.T) {
3131

3232
args := []string{
3333
"--schedule-period=5m",
34+
"--priority-class=false",
3435
}
3536
fs.Parse(args)
3637

cmd/kube-batch/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum
3939
func main() {
4040
s := options.NewServerOption()
4141
s.AddFlags(pflag.CommandLine)
42+
s.RegisterOptions()
4243

4344
flag.InitFlags()
4445
if err := s.CheckOptionOrDie(); err != nil {

pkg/scheduler/cache/cache.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
4545
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
4646

47+
"github.com/kubernetes-sigs/kube-batch/cmd/kube-batch/app/options"
4748
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
4849
kbver "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
4950
"github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/scheme"
@@ -304,7 +305,10 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
304305
go sc.pvcInformer.Informer().Run(stopCh)
305306
go sc.scInformer.Informer().Run(stopCh)
306307
go sc.queueInformer.Informer().Run(stopCh)
307-
go sc.pcInformer.Informer().Run(stopCh)
308+
309+
if options.ServerOpts.EnablePriorityClass {
310+
go sc.pcInformer.Informer().Run(stopCh)
311+
}
308312

309313
// Re-sync error tasks.
310314
go wait.Until(sc.processResyncTask, 0, stopCh)
@@ -316,15 +320,22 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
316320
func (sc *SchedulerCache) WaitForCacheSync(stopCh <-chan struct{}) bool {
317321

318322
return cache.WaitForCacheSync(stopCh,
319-
sc.pdbInformer.Informer().HasSynced,
320-
sc.podInformer.Informer().HasSynced,
321-
sc.podGroupInformer.Informer().HasSynced,
322-
sc.nodeInformer.Informer().HasSynced,
323-
sc.pvInformer.Informer().HasSynced,
324-
sc.pvcInformer.Informer().HasSynced,
325-
sc.scInformer.Informer().HasSynced,
326-
sc.queueInformer.Informer().HasSynced,
327-
sc.pcInformer.Informer().HasSynced,
323+
func() []cache.InformerSynced {
324+
informerSynced := []cache.InformerSynced{
325+
sc.pdbInformer.Informer().HasSynced,
326+
sc.podInformer.Informer().HasSynced,
327+
sc.podGroupInformer.Informer().HasSynced,
328+
sc.nodeInformer.Informer().HasSynced,
329+
sc.pvInformer.Informer().HasSynced,
330+
sc.pvcInformer.Informer().HasSynced,
331+
sc.scInformer.Informer().HasSynced,
332+
sc.queueInformer.Informer().HasSynced,
333+
}
334+
if options.ServerOpts.EnablePriorityClass {
335+
informerSynced = append(informerSynced, sc.pcInformer.Informer().HasSynced)
336+
}
337+
return informerSynced
338+
}()...,
328339
)
329340
}
330341

0 commit comments

Comments
 (0)