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

Commit 4a2be8e

Browse files
authored
Merge pull request #414 from k82cn/kb_412
Added --schedule-period
2 parents a6f99c5 + 11c2a3b commit 4a2be8e

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package options
1818

1919
import (
2020
"fmt"
21+
"time"
2122

2223
"github.com/spf13/pflag"
2324
)
@@ -28,6 +29,7 @@ type ServerOption struct {
2829
Kubeconfig string
2930
SchedulerName string
3031
SchedulerConf string
32+
SchedulePeriod string
3133
NamespaceAsQueue bool
3234
EnableLeaderElection bool
3335
LockObjectNamespace string
@@ -46,6 +48,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
4648
// kube-batch will ignore pods with scheduler names other than specified with the option
4749
fs.StringVar(&s.SchedulerName, "scheduler-name", "kube-batch", "kube-batch will handle pods with the scheduler-name")
4850
fs.StringVar(&s.SchedulerConf, "scheduler-conf", "", "The namespace and name of ConfigMap for scheduler configuration")
51+
fs.StringVar(&s.SchedulePeriod, "schedule-period", "1s", "The period between each scheduling cycle")
4952
fs.BoolVar(&s.EnableLeaderElection, "leader-elect", s.EnableLeaderElection, "Start a leader election client and gain leadership before "+
5053
"executing the main loop. Enable this when running replicated kube-batch for high availability")
5154
fs.BoolVar(&s.NamespaceAsQueue, "enable-namespace-as-queue", true, "Make Namespace as Queue with weight one, "+
@@ -57,5 +60,9 @@ func (s *ServerOption) CheckOptionOrDie() error {
5760
if s.EnableLeaderElection && s.LockObjectNamespace == "" {
5861
return fmt.Errorf("lock-object-namespace must not be nil when LeaderElection is enabled")
5962
}
63+
if _, err := time.ParseDuration(s.SchedulePeriod); err != nil {
64+
return fmt.Errorf("failed to parse --schedule-period: %v", err)
65+
}
66+
6067
return nil
6168
}

cmd/kube-batch/app/server.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func Run(opt *options.ServerOption) error {
6060
neverStop := make(chan struct{})
6161

6262
// Start policy controller to allocate resources.
63-
sched, err := scheduler.NewScheduler(config, opt.SchedulerName, opt.SchedulerConf, opt.NamespaceAsQueue)
63+
sched, err := scheduler.NewScheduler(config, opt.SchedulerName,
64+
opt.SchedulerConf, opt.SchedulePeriod, opt.NamespaceAsQueue)
6465
if err != nil {
6566
panic(err)
6667
}

pkg/scheduler/scheduler.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@ import (
2929
)
3030

3131
type Scheduler struct {
32-
cache schedcache.Cache
33-
config *rest.Config
34-
actions []framework.Action
35-
pluginArgs []*framework.PluginArgs
36-
schedulerConf string
32+
cache schedcache.Cache
33+
config *rest.Config
34+
actions []framework.Action
35+
pluginArgs []*framework.PluginArgs
36+
schedulerConf string
37+
schedulePeriod time.Duration
3738
}
3839

3940
func NewScheduler(
4041
config *rest.Config,
4142
schedulerName string,
4243
conf string,
44+
period string,
4345
nsAsQueue bool,
4446
) (*Scheduler, error) {
47+
sp, _ := time.ParseDuration(period)
4548
scheduler := &Scheduler{
46-
config: config,
47-
schedulerConf: conf,
48-
cache: schedcache.New(config, schedulerName, nsAsQueue),
49+
config: config,
50+
schedulerConf: conf,
51+
cache: schedcache.New(config, schedulerName, nsAsQueue),
52+
schedulePeriod: sp,
4953
}
5054

5155
return scheduler, nil
@@ -69,7 +73,7 @@ func (pc *Scheduler) Run(stopCh <-chan struct{}) {
6973

7074
pc.actions, pc.pluginArgs = loadSchedulerConf(conf)
7175

72-
go wait.Until(pc.runOnce, 1*time.Second, stopCh)
76+
go wait.Until(pc.runOnce, pc.schedulePeriod, stopCh)
7377
}
7478

7579
func (pc *Scheduler) runOnce() {

0 commit comments

Comments
 (0)