@@ -25,13 +25,15 @@ import (
25
25
"github.com/golang/glog"
26
26
27
27
"k8s.io/api/core/v1"
28
+ "k8s.io/api/scheduling/v1beta1"
28
29
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
30
"k8s.io/apimachinery/pkg/runtime"
30
31
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
31
32
"k8s.io/apimachinery/pkg/util/wait"
32
33
"k8s.io/client-go/informers"
33
34
infov1 "k8s.io/client-go/informers/core/v1"
34
35
policyv1 "k8s.io/client-go/informers/policy/v1beta1"
36
+ schedv1 "k8s.io/client-go/informers/scheduling/v1beta1"
35
37
storagev1 "k8s.io/client-go/informers/storage/v1"
36
38
"k8s.io/client-go/kubernetes"
37
39
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -82,6 +84,7 @@ type SchedulerCache struct {
82
84
pvInformer infov1.PersistentVolumeInformer
83
85
pvcInformer infov1.PersistentVolumeClaimInformer
84
86
scInformer storagev1.StorageClassInformer
87
+ pcInformer schedv1.PriorityClassInformer
85
88
86
89
Binder Binder
87
90
Evictor Evictor
@@ -90,9 +93,12 @@ type SchedulerCache struct {
90
93
91
94
Recorder record.EventRecorder
92
95
93
- Jobs map [kbapi.JobID ]* kbapi.JobInfo
94
- Nodes map [string ]* kbapi.NodeInfo
95
- Queues map [kbapi.QueueID ]* kbapi.QueueInfo
96
+ Jobs map [kbapi.JobID ]* kbapi.JobInfo
97
+ Nodes map [string ]* kbapi.NodeInfo
98
+ Queues map [kbapi.QueueID ]* kbapi.QueueInfo
99
+ PriorityClasses map [string ]* v1beta1.PriorityClass
100
+ defaultPriorityClass * v1beta1.PriorityClass
101
+ defaultPriority int32
96
102
97
103
errTasks workqueue.RateLimitingInterface
98
104
deletedJobs workqueue.RateLimitingInterface
@@ -179,14 +185,15 @@ func (dvb *defaultVolumeBinder) BindVolumes(task *api.TaskInfo) error {
179
185
180
186
func newSchedulerCache (config * rest.Config , schedulerName string , defaultQueue string ) * SchedulerCache {
181
187
sc := & SchedulerCache {
182
- Jobs : make (map [kbapi.JobID ]* kbapi.JobInfo ),
183
- Nodes : make (map [string ]* kbapi.NodeInfo ),
184
- Queues : make (map [kbapi.QueueID ]* kbapi.QueueInfo ),
185
- errTasks : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
186
- deletedJobs : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
187
- kubeclient : kubernetes .NewForConfigOrDie (config ),
188
- kbclient : kbver .NewForConfigOrDie (config ),
189
- defaultQueue : defaultQueue ,
188
+ Jobs : make (map [kbapi.JobID ]* kbapi.JobInfo ),
189
+ Nodes : make (map [string ]* kbapi.NodeInfo ),
190
+ Queues : make (map [kbapi.QueueID ]* kbapi.QueueInfo ),
191
+ PriorityClasses : make (map [string ]* v1beta1.PriorityClass ),
192
+ errTasks : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
193
+ deletedJobs : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
194
+ kubeclient : kubernetes .NewForConfigOrDie (config ),
195
+ kbclient : kbver .NewForConfigOrDie (config ),
196
+ defaultQueue : defaultQueue ,
190
197
}
191
198
192
199
// Prepare event clients.
@@ -263,6 +270,13 @@ func newSchedulerCache(config *rest.Config, schedulerName string, defaultQueue s
263
270
DeleteFunc : sc .DeletePDB ,
264
271
})
265
272
273
+ sc .pcInformer = informerFactory .Scheduling ().V1beta1 ().PriorityClasses ()
274
+ sc .pcInformer .Informer ().AddEventHandler (cache.ResourceEventHandlerFuncs {
275
+ AddFunc : sc .AddPriorityClass ,
276
+ UpdateFunc : sc .UpdatePriorityClass ,
277
+ DeleteFunc : sc .DeletePriorityClass ,
278
+ })
279
+
266
280
kbinformer := kbinfo .NewSharedInformerFactory (sc .kbclient , 0 )
267
281
// create informer for PodGroup information
268
282
sc .podGroupInformer = kbinformer .Scheduling ().V1alpha1 ().PodGroups ()
@@ -292,6 +306,7 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
292
306
go sc .pvcInformer .Informer ().Run (stopCh )
293
307
go sc .scInformer .Informer ().Run (stopCh )
294
308
go sc .queueInformer .Informer ().Run (stopCh )
309
+ go sc .pcInformer .Informer ().Run (stopCh )
295
310
296
311
// Re-sync error tasks.
297
312
go wait .Until (sc .processResyncTask , 0 , stopCh )
@@ -311,6 +326,7 @@ func (sc *SchedulerCache) WaitForCacheSync(stopCh <-chan struct{}) bool {
311
326
sc .pvcInformer .Informer ().HasSynced ,
312
327
sc .scInformer .Informer ().HasSynced ,
313
328
sc .queueInformer .Informer ().HasSynced ,
329
+ sc .pcInformer .Informer ().HasSynced ,
314
330
)
315
331
}
316
332
@@ -527,6 +543,15 @@ func (sc *SchedulerCache) Snapshot() *kbapi.ClusterInfo {
527
543
continue
528
544
}
529
545
546
+ if value .PodGroup != nil {
547
+ value .Priority = sc .defaultPriority
548
+
549
+ priName := value .PodGroup .Spec .PriorityClassName
550
+ if priorityClass , found := sc .PriorityClasses [priName ]; found {
551
+ value .Priority = priorityClass .Value
552
+ }
553
+ }
554
+
530
555
snapshot .Jobs [value .UID ] = value .Clone ()
531
556
}
532
557
0 commit comments