15
15
package controller
16
16
17
17
import (
18
+ "reflect"
19
+ "sort"
18
20
"testing"
19
21
20
22
"github.com/google/go-cmp/cmp"
@@ -183,6 +185,10 @@ func TestNewPodGroup(t *testing.T) {
183
185
MinMember : 3 ,
184
186
Queue : "project-x" ,
185
187
PriorityClassName : "high" ,
188
+ MinResources : & corev1.ResourceList {
189
+ corev1 .ResourceCPU : resource .MustParse ("21" ),
190
+ corev1 .ResourceMemory : resource .MustParse ("42Gi" ),
191
+ },
186
192
},
187
193
},
188
194
wantSchedPG : & schedv1alpha1.PodGroup {
@@ -207,8 +213,10 @@ func TestNewPodGroup(t *testing.T) {
207
213
for name , tc := range testCases {
208
214
t .Run (name , func (t * testing.T ) {
209
215
volcanoFixture := newFixture (t , "default-scheduler" )
216
+ jobController , _ , _ := volcanoFixture .newController (clock.RealClock {})
210
217
volcanoPGCtrl := & VolcanoCtrl {
211
- Client : volcanoFixture .volcanoClient ,
218
+ Client : volcanoFixture .volcanoClient ,
219
+ PriorityClassLister : jobController .priorityClassLister ,
212
220
}
213
221
volcanoPG := volcanoPGCtrl .newPodGroup (tc .mpiJob )
214
222
if diff := cmp .Diff (tc .wantVolcanoPG , volcanoPG , ignoreReferences ); len (diff ) != 0 {
@@ -361,8 +369,10 @@ func TestDecoratePodTemplateSpec(t *testing.T) {
361
369
362
370
func TestCalculatePGMinResources (t * testing.T ) {
363
371
volcanoTests := map [string ]struct {
364
- job * kubeflow.MPIJob
365
- want * corev1.ResourceList
372
+ job * kubeflow.MPIJob
373
+ priorityClasses []* schedulingv1.PriorityClass
374
+ minMember int32
375
+ want * corev1.ResourceList
366
376
}{
367
377
"minResources is not empty" : {
368
378
job : & kubeflow.MPIJob {
@@ -388,12 +398,68 @@ func TestCalculatePGMinResources(t *testing.T) {
388
398
},
389
399
want : nil ,
390
400
},
401
+ "without priorityClass" : {
402
+ minMember : 3 ,
403
+ job : & kubeflow.MPIJob {
404
+ ObjectMeta : metav1.ObjectMeta {
405
+ Name : "test" ,
406
+ },
407
+ Spec : kubeflow.MPIJobSpec {
408
+ MPIReplicaSpecs : map [kubeflow.MPIReplicaType ]* common.ReplicaSpec {
409
+ kubeflow .MPIReplicaTypeLauncher : {
410
+ Replicas : pointer .Int32 (1 ),
411
+ Template : corev1.PodTemplateSpec {
412
+ Spec : corev1.PodSpec {
413
+ Containers : []corev1.Container {
414
+ {
415
+ Resources : corev1.ResourceRequirements {
416
+ Requests : corev1.ResourceList {
417
+ corev1 .ResourceCPU : resource .MustParse ("2" ),
418
+ corev1 .ResourceMemory : resource .MustParse ("1Gi" ),
419
+ },
420
+ },
421
+ },
422
+ },
423
+ },
424
+ },
425
+ },
426
+ kubeflow .MPIReplicaTypeWorker : {
427
+ Replicas : pointer .Int32 (2 ),
428
+ Template : corev1.PodTemplateSpec {
429
+ Spec : corev1.PodSpec {
430
+ Containers : []corev1.Container {
431
+ {
432
+ Resources : corev1.ResourceRequirements {
433
+ Requests : corev1.ResourceList {
434
+ corev1 .ResourceCPU : resource .MustParse ("10" ),
435
+ corev1 .ResourceMemory : resource .MustParse ("32Gi" ),
436
+ },
437
+ },
438
+ },
439
+ },
440
+ },
441
+ },
442
+ },
443
+ },
444
+ },
445
+ },
446
+ want : & corev1.ResourceList {
447
+ corev1 .ResourceCPU : resource .MustParse ("22" ),
448
+ corev1 .ResourceMemory : resource .MustParse ("65Gi" ),
449
+ },
450
+ },
391
451
}
392
452
for name , tc := range volcanoTests {
393
453
t .Run (name , func (t * testing.T ) {
394
- f := newFixture (t , "scheduler-plugins-scheduler" )
395
- pgCtrl := VolcanoCtrl {Client : f .volcanoClient }
396
- got := pgCtrl .calculatePGMinResources (pointer .Int32 (0 ), tc .job )
454
+ f := newFixture (t , "volcano-scheduler" )
455
+ if tc .priorityClasses != nil {
456
+ for _ , pc := range tc .priorityClasses {
457
+ f .setUpPriorityClass (pc )
458
+ }
459
+ }
460
+ jobController , _ , _ := f .newController (clock.RealClock {})
461
+ pgCtrl := VolcanoCtrl {Client : f .volcanoClient , PriorityClassLister : jobController .priorityClassLister }
462
+ got := pgCtrl .calculatePGMinResources (& tc .minMember , tc .job )
397
463
if diff := cmp .Diff (tc .want , got ); len (diff ) != 0 {
398
464
t .Fatalf ("Unexpected calculatePGMinResources for the volcano (-want,+got):\n %s" , diff )
399
465
}
@@ -752,3 +818,40 @@ func TestCalculateMinAvailable(t *testing.T) {
752
818
})
753
819
}
754
820
}
821
+
822
+ func TestReplicasOrder (t * testing.T ) {
823
+ var lancherReplic , wokerReplic int32 = 1 , 2
824
+ tests := map [string ]struct {
825
+ original replicasOrder
826
+ expected replicasOrder
827
+ }{
828
+ "1-lancher, 2-worker, lancher higher priority" : {
829
+ original : replicasOrder {
830
+ {priority : 1 , replicaType : kubeflow .MPIReplicaTypeLauncher , ReplicaSpec : common.ReplicaSpec {Replicas : & lancherReplic }},
831
+ {priority : 0 , replicaType : kubeflow .MPIReplicaTypeWorker , ReplicaSpec : common.ReplicaSpec {Replicas : & wokerReplic }},
832
+ },
833
+ expected : replicasOrder {
834
+ {priority : 1 , replicaType : kubeflow .MPIReplicaTypeLauncher , ReplicaSpec : common.ReplicaSpec {Replicas : & lancherReplic }},
835
+ {priority : 0 , replicaType : kubeflow .MPIReplicaTypeWorker , ReplicaSpec : common.ReplicaSpec {Replicas : & wokerReplic }},
836
+ },
837
+ },
838
+ "1-lancher, 2-worker, equal priority" : {
839
+ original : replicasOrder {
840
+ {priority : 0 , replicaType : kubeflow .MPIReplicaTypeWorker , ReplicaSpec : common.ReplicaSpec {Replicas : & wokerReplic }},
841
+ {priority : 0 , replicaType : kubeflow .MPIReplicaTypeLauncher , ReplicaSpec : common.ReplicaSpec {Replicas : & lancherReplic }},
842
+ },
843
+ expected : replicasOrder {
844
+ {priority : 0 , replicaType : kubeflow .MPIReplicaTypeWorker , ReplicaSpec : common.ReplicaSpec {Replicas : & wokerReplic }},
845
+ {priority : 0 , replicaType : kubeflow .MPIReplicaTypeLauncher , ReplicaSpec : common.ReplicaSpec {Replicas : & lancherReplic }},
846
+ },
847
+ },
848
+ }
849
+ for name , tc := range tests {
850
+ t .Run (name , func (t * testing.T ) {
851
+ sort .Sort (sort .Reverse (tc .original ))
852
+ if ! reflect .DeepEqual (tc .original , tc .expected ) {
853
+ t .Fatalf ("Unexpected sort list (-want,+got):\n -want:%v\n +got:%v" , tc .expected , tc .original )
854
+ }
855
+ })
856
+ }
857
+ }
0 commit comments