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

Commit 10b96b8

Browse files
Handle v1alpha2 version of queue in kube-batch
1 parent f4e9918 commit 10b96b8

File tree

8 files changed

+292
-28
lines changed

8 files changed

+292
-28
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: queues.scheduling.sigs.dev
5+
spec:
6+
group: scheduling.sigs.dev
7+
names:
8+
kind: Queue
9+
plural: queues
10+
scope: Cluster
11+
validation:
12+
openAPIV3Schema:
13+
properties:
14+
apiVersion:
15+
type: string
16+
kind:
17+
type: string
18+
metadata:
19+
type: object
20+
spec:
21+
properties:
22+
weight:
23+
format: int32
24+
type: integer
25+
type: object
26+
status:
27+
properties:
28+
unknown:
29+
format: int32
30+
type: integer
31+
pending:
32+
format: int32
33+
type: integer
34+
running:
35+
format: int32
36+
type: integer
37+
type: object
38+
type: object
39+
version: v1alpha2

hack/run-e2e-kind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function kube-batch-up {
7272
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha1_queue.yaml
7373
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha1_podgroup.yaml
7474
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha2_podgroup.yaml
75+
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha2_queue.yaml
7576
kubectl create -f deployment/kube-batch/templates/default.yaml
7677

7778
# start kube-batch
@@ -87,4 +88,3 @@ kube-batch-up
8788

8889
cd ${ROOT_DIR}
8990
go test ./test/e2e -v -timeout 30m
90-

pkg/scheduler/actions/allocate/allocate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestAllocate(t *testing.T) {
173173
}
174174

175175
for _, q := range test.queues {
176-
schedulerCache.AddQueue(q)
176+
schedulerCache.AddQueuev1alpha1(q)
177177
}
178178

179179
trueValue := true

pkg/scheduler/actions/preempt/preempt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestPreempt(t *testing.T) {
165165
}
166166

167167
for _, q := range test.queues {
168-
schedulerCache.AddQueue(q)
168+
schedulerCache.AddQueuev1alpha1(q)
169169
}
170170

171171
trueValue := true

pkg/scheduler/actions/reclaim/reclaim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestReclaim(t *testing.T) {
134134
}
135135

136136
for _, q := range test.queues {
137-
schedulerCache.AddQueue(q)
137+
schedulerCache.AddQueuev1alpha1(q)
138138
}
139139

140140
trueValue := true

pkg/scheduler/api/queue_info.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,56 @@ limitations under the License.
1717
package api
1818

1919
import (
20+
v1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2022
"k8s.io/apimachinery/pkg/types"
23+
)
24+
25+
const (
26+
//QueueVersionV1Alpha1 represents PodGroupVersion of V1Alpha1
27+
QueueVersionV1Alpha1 string = "v1alpha1"
2128

22-
arbcorev1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
29+
//QueueVersionV1Alpha2 represents PodGroupVersion of V1Alpha2
30+
QueueVersionV1Alpha2 string = "v1alpha2"
2331
)
2432

33+
// Queue is a queue of PodGroup.
34+
type Queue struct {
35+
metav1.TypeMeta `json:",inline"`
36+
// Standard object's metadata.
37+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
38+
// +optional
39+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
40+
41+
// Specification of the desired behavior of the queue.
42+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
43+
// +optional
44+
Spec QueueSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
45+
46+
// The status of queue.
47+
// +optional
48+
Status QueueStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
49+
50+
//Version is used to retrieve information about queue version
51+
Version string
52+
}
53+
54+
// QueueStatus represents the status of Queue.
55+
type QueueStatus struct {
56+
// The number of 'Unknonw' PodGroup in this queue.
57+
Unknown int32 `json:"unknown,omitempty" protobuf:"bytes,1,opt,name=unknown"`
58+
// The number of 'Pending' PodGroup in this queue.
59+
Pending int32 `json:"pending,omitempty" protobuf:"bytes,2,opt,name=pending"`
60+
// The number of 'Running' PodGroup in this queue.
61+
Running int32 `json:"running,omitempty" protobuf:"bytes,3,opt,name=running"`
62+
}
63+
64+
// QueueSpec represents the template of Queue.
65+
type QueueSpec struct {
66+
Weight int32 `json:"weight,omitempty" protobuf:"bytes,1,opt,name=weight"`
67+
Capability v1.ResourceList `json:"capability,omitempty" protobuf:"bytes,2,opt,name=capability"`
68+
}
69+
2570
// QueueID is UID type, serves as unique ID for each queue
2671
type QueueID types.UID
2772

@@ -32,11 +77,11 @@ type QueueInfo struct {
3277

3378
Weight int32
3479

35-
Queue *arbcorev1.Queue
80+
Queue *Queue
3681
}
3782

3883
// NewQueueInfo creates new queueInfo object
39-
func NewQueueInfo(queue *arbcorev1.Queue) *QueueInfo {
84+
func NewQueueInfo(queue *Queue) *QueueInfo {
4085
return &QueueInfo{
4186
UID: QueueID(queue.Name),
4287
Name: queue.Name,

pkg/scheduler/cache/cache.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ type SchedulerCache struct {
8686
nsInformer infov1.NamespaceInformer
8787
podGroupInformerv1alpha1 kbinfov1.PodGroupInformer
8888
podGroupInformerv1alpha2 kbinfov2.PodGroupInformer
89-
queueInformer kbinfov1.QueueInformer
89+
queueInformerv1alpha1 kbinfov1.QueueInformer
90+
queueInformerv1alpha2 kbinfov2.QueueInformer
9091
pvInformer infov1.PersistentVolumeInformer
9192
pvcInformer infov1.PersistentVolumeClaimInformer
9293
scInformer storagev1.StorageClassInformer
@@ -331,12 +332,20 @@ func newSchedulerCache(config *rest.Config, schedulerName string, defaultQueue s
331332
DeleteFunc: sc.DeletePodGroupAlpha2,
332333
})
333334

334-
// create informer for Queue information
335-
sc.queueInformer = kbinformer.Scheduling().V1alpha1().Queues()
336-
sc.queueInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
337-
AddFunc: sc.AddQueue,
338-
UpdateFunc: sc.UpdateQueue,
339-
DeleteFunc: sc.DeleteQueue,
335+
// create informer for Queue(v1alpha1) information
336+
sc.queueInformerv1alpha1 = kbinformer.Scheduling().V1alpha1().Queues()
337+
sc.queueInformerv1alpha1.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
338+
AddFunc: sc.AddQueuev1alpha1,
339+
UpdateFunc: sc.UpdateQueuev1alpha1,
340+
DeleteFunc: sc.DeleteQueuev1alpha1,
341+
})
342+
343+
// create informer for Queue(v1alpha2) information
344+
sc.queueInformerv1alpha2 = kbinformer.Scheduling().V1alpha2().Queues()
345+
sc.queueInformerv1alpha2.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
346+
AddFunc: sc.AddQueuev1alpha2,
347+
UpdateFunc: sc.UpdateQueuev1alpha2,
348+
DeleteFunc: sc.DeleteQueuev1alpha2,
340349
})
341350

342351
return sc
@@ -352,7 +361,8 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
352361
go sc.pvInformer.Informer().Run(stopCh)
353362
go sc.pvcInformer.Informer().Run(stopCh)
354363
go sc.scInformer.Informer().Run(stopCh)
355-
go sc.queueInformer.Informer().Run(stopCh)
364+
go sc.queueInformerv1alpha1.Informer().Run(stopCh)
365+
go sc.queueInformerv1alpha2.Informer().Run(stopCh)
356366

357367
if options.ServerOpts.EnablePriorityClass {
358368
go sc.pcInformer.Informer().Run(stopCh)
@@ -379,7 +389,8 @@ func (sc *SchedulerCache) WaitForCacheSync(stopCh <-chan struct{}) bool {
379389
sc.pvInformer.Informer().HasSynced,
380390
sc.pvcInformer.Informer().HasSynced,
381391
sc.scInformer.Informer().HasSynced,
382-
sc.queueInformer.Informer().HasSynced,
392+
sc.queueInformerv1alpha1.Informer().HasSynced,
393+
sc.queueInformerv1alpha2.Informer().HasSynced,
383394
}
384395
if options.ServerOpts.EnablePriorityClass {
385396
informerSynced = append(informerSynced, sc.pcInformer.Informer().HasSynced)

0 commit comments

Comments
 (0)