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

Commit 6a334ee

Browse files
authored
Merge pull request #465 from adam-marek/amarek-pdb-queue
Enable PDB based gang scheduling with discrete queues.
2 parents 5b1b769 + 015d433 commit 6a334ee

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ type ServerOption struct {
3333
NamespaceAsQueue bool
3434
EnableLeaderElection bool
3535
LockObjectNamespace string
36+
DefaultQueue string
37+
}
38+
39+
var (
40+
opts *ServerOption
41+
)
42+
43+
func Options() *ServerOption {
44+
if opts == nil {
45+
opts = &ServerOption{}
46+
}
47+
return opts
3648
}
3749

3850
// NewServerOption creates a new CMServer with a default config.
@@ -49,6 +61,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
4961
fs.StringVar(&s.SchedulerName, "scheduler-name", "kube-batch", "kube-batch will handle pods with the scheduler-name")
5062
fs.StringVar(&s.SchedulerConf, "scheduler-conf", "", "The namespace and name of ConfigMap for scheduler configuration")
5163
fs.StringVar(&s.SchedulePeriod, "schedule-period", "1s", "The period between each scheduling cycle")
64+
fs.StringVar(&s.DefaultQueue, "default-queue", "", "The name of the queue to fall-back to instead of namespace name")
5265
fs.BoolVar(&s.EnableLeaderElection, "leader-elect", s.EnableLeaderElection, "Start a leader election client and gain leadership before "+
5366
"executing the main loop. Enable this when running replicated kube-batch for high availability")
5467
fs.BoolVar(&s.NamespaceAsQueue, "enable-namespace-as-queue", true, "Make Namespace as Queue with weight one, "+

cmd/kube-batch/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
3434

3535
func main() {
36-
s := options.NewServerOption()
36+
s := options.Options()
3737
s.AddFlags(pflag.CommandLine)
3838

3939
flag.InitFlags()

pkg/scheduler/api/job_info.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/types"
2525

26+
"github.com/kubernetes-sigs/kube-batch/cmd/kube-batch/app/options"
2627
arbcorev1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
2728
"github.com/kubernetes-sigs/kube-batch/pkg/apis/utils"
2829
)
@@ -159,10 +160,17 @@ func (ji *JobInfo) SetPodGroup(pg *arbcorev1.PodGroup) {
159160
ji.Namespace = pg.Namespace
160161
ji.MinAvailable = pg.Spec.MinMember
161162

162-
if len(pg.Spec.Queue) == 0 {
163-
ji.Queue = QueueID(pg.Namespace)
164-
} else {
163+
//set queue name based on the available information
164+
//in the following priority order:
165+
// 1. queue name from PodGroup spec (if available)
166+
// 2. queue name from default-queue command line option (if specified)
167+
// 3. namespace name
168+
if len(pg.Spec.Queue) > 0 {
165169
ji.Queue = QueueID(pg.Spec.Queue)
170+
} else if len(options.Options().DefaultQueue) > 0 {
171+
ji.Queue = QueueID(options.Options().DefaultQueue)
172+
} else {
173+
ji.Queue = QueueID(pg.Namespace)
166174
}
167175

168176
ji.CreationTimestamp = pg.GetCreationTimestamp()
@@ -173,7 +181,11 @@ func (ji *JobInfo) SetPDB(pdb *policyv1.PodDisruptionBudget) {
173181
ji.Name = pdb.Name
174182
ji.MinAvailable = pdb.Spec.MinAvailable.IntVal
175183
ji.Namespace = pdb.Namespace
176-
ji.Queue = QueueID(pdb.Namespace)
184+
if len(options.Options().DefaultQueue) == 0 {
185+
ji.Queue = QueueID(pdb.Namespace)
186+
} else {
187+
ji.Queue = QueueID(options.Options().DefaultQueue)
188+
}
177189

178190
ji.CreationTimestamp = pdb.GetCreationTimestamp()
179191
ji.PDB = pdb

0 commit comments

Comments
 (0)