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

add options to enable the feature of PriorityClass #725

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/kube-batch/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ type ServerOption struct {
DefaultQueue string
PrintVersion bool
ListenAddress string
EnablePriorityClass bool
}

var ServerOpts *ServerOption

// NewServerOption creates a new CMServer with a default config.
func NewServerOption() *ServerOption {
s := ServerOption{}
Expand All @@ -65,6 +68,8 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&s.PrintVersion, "version", false, "Show version and quit")
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object that is used for leader election")
fs.StringVar(&s.ListenAddress, "listen-address", defaultListenAddress, "The address to listen on for HTTP requests.")
fs.BoolVar(&s.EnablePriorityClass, "priority-class", true,
"Enable PriorityClass to provide the capacity of preemption at pod group level; to disable it, set it false")
}

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

return nil
}

func (s *ServerOption) RegisterOptions() {
ServerOpts = s
}
1 change: 1 addition & 0 deletions cmd/kube-batch/app/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAddFlags(t *testing.T) {

args := []string{
"--schedule-period=5m",
"--priority-class=false",
}
fs.Parse(args)

Expand Down
1 change: 1 addition & 0 deletions cmd/kube-batch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum
func main() {
s := options.NewServerOption()
s.AddFlags(pflag.CommandLine)
s.RegisterOptions()

flag.InitFlags()
if err := s.CheckOptionOrDie(); err != nil {
Expand Down
31 changes: 21 additions & 10 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"

"github.com/kubernetes-sigs/kube-batch/cmd/kube-batch/app/options"
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
kbver "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
"github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/scheme"
Expand Down Expand Up @@ -304,7 +305,10 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
go sc.pvcInformer.Informer().Run(stopCh)
go sc.scInformer.Informer().Run(stopCh)
go sc.queueInformer.Informer().Run(stopCh)
go sc.pcInformer.Informer().Run(stopCh)

if options.ServerOpts.EnablePriorityClass {
go sc.pcInformer.Informer().Run(stopCh)
}

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

return cache.WaitForCacheSync(stopCh,
sc.pdbInformer.Informer().HasSynced,
sc.podInformer.Informer().HasSynced,
sc.podGroupInformer.Informer().HasSynced,
sc.nodeInformer.Informer().HasSynced,
sc.pvInformer.Informer().HasSynced,
sc.pvcInformer.Informer().HasSynced,
sc.scInformer.Informer().HasSynced,
sc.queueInformer.Informer().HasSynced,
sc.pcInformer.Informer().HasSynced,
func() []cache.InformerSynced {
informerSynced := []cache.InformerSynced{
sc.pdbInformer.Informer().HasSynced,
sc.podInformer.Informer().HasSynced,
sc.podGroupInformer.Informer().HasSynced,
sc.nodeInformer.Informer().HasSynced,
sc.pvInformer.Informer().HasSynced,
sc.pvcInformer.Informer().HasSynced,
sc.scInformer.Informer().HasSynced,
sc.queueInformer.Informer().HasSynced,
}
if options.ServerOpts.EnablePriorityClass {
informerSynced = append(informerSynced, sc.pcInformer.Informer().HasSynced)
}
return informerSynced
}()...,
)
}

Expand Down