@@ -31,6 +31,7 @@ import (
31
31
"k8s.io/apimachinery/pkg/runtime"
32
32
"k8s.io/apimachinery/pkg/types"
33
33
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
34
+ "k8s.io/utils/ptr"
34
35
"sigs.k8s.io/controller-runtime/pkg/client/fake"
35
36
36
37
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
@@ -53,7 +54,7 @@ type mockSaturationDetector struct {
53
54
isSaturated bool
54
55
}
55
56
56
- func (m * mockSaturationDetector ) IsSaturated (_ context.Context ) bool {
57
+ func (m * mockSaturationDetector ) IsSaturated (_ context.Context , _ []backendmetrics. PodMetrics ) bool {
57
58
return m .isSaturated
58
59
}
59
60
@@ -66,6 +67,23 @@ func (m *mockScheduler) Schedule(_ context.Context, _ *schedulingtypes.LLMReques
66
67
return m .scheduleResults , m .scheduleErr
67
68
}
68
69
70
+ type mockDatastore struct {
71
+ pods []backendmetrics.PodMetrics
72
+ }
73
+
74
+ func (ds * mockDatastore ) PoolGet () (* v1.InferencePool , error ) { return nil , nil }
75
+ func (ds * mockDatastore ) ObjectiveGet (_ string ) * v1alpha2.InferenceObjective { return nil }
76
+ func (ds * mockDatastore ) PodList (predicate func (backendmetrics.PodMetrics ) bool ) []backendmetrics.PodMetrics {
77
+ res := []backendmetrics.PodMetrics {}
78
+ for _ , pod := range ds .pods {
79
+ if predicate (pod ) {
80
+ res = append (res , pod )
81
+ }
82
+ }
83
+
84
+ return res
85
+ }
86
+
69
87
func TestDirector_HandleRequest (t * testing.T ) {
70
88
ctx := logutil .NewTestLoggerIntoContext (context .Background ())
71
89
@@ -425,125 +443,78 @@ func TestDirector_HandleRequest(t *testing.T) {
425
443
func TestGetCandidatePodsForScheduling (t * testing.T ) {
426
444
var makeFilterMetadata = func (data []any ) map [string ]any {
427
445
return map [string ]any {
428
- "envoy.lb.subset_hint" : map [string ]any {
429
- "x-gateway-destination-endpoint-subset" : data ,
446
+ subsetHintNamespace : map [string ]any {
447
+ subsetHintKey : data ,
430
448
},
431
449
}
432
450
}
433
451
434
- testInput := []* corev1.Pod {
435
- {
436
- ObjectMeta : metav1.ObjectMeta {
437
- Name : "pod1" ,
438
- },
439
- Status : corev1.PodStatus {
440
- PodIP : "10.0.0.1" ,
441
- },
442
- },
443
- {
444
- ObjectMeta : metav1.ObjectMeta {
445
- Name : "pod2" ,
446
- },
447
- Status : corev1.PodStatus {
448
- PodIP : "10.0.0.2" ,
449
- },
450
- },
451
- }
452
-
453
- outputPod1 := & backend.Pod {
452
+ pod1 := & backend.Pod {
454
453
NamespacedName : types.NamespacedName {Name : "pod1" },
455
454
Address : "10.0.0.1" ,
456
455
Labels : map [string ]string {},
457
456
}
458
457
459
- outputPod2 := & backend.Pod {
458
+ pod2 := & backend.Pod {
460
459
NamespacedName : types.NamespacedName {Name : "pod2" },
461
460
Address : "10.0.0.2" ,
462
461
Labels : map [string ]string {},
463
462
}
464
463
464
+ testInput := []backendmetrics.PodMetrics {
465
+ & backendmetrics.FakePodMetrics {Pod : pod1 },
466
+ & backendmetrics.FakePodMetrics {Pod : pod2 },
467
+ }
468
+
465
469
tests := []struct {
466
470
name string
467
471
metadata map [string ]any
468
- output []schedulingtypes. Pod
472
+ output []backendmetrics. PodMetrics
469
473
}{
470
474
{
471
475
name : "SubsetFilter, filter not present — return all pods" ,
472
476
metadata : map [string ]any {},
473
- output : []schedulingtypes.Pod {
474
- & schedulingtypes.PodMetrics {
475
- Pod : outputPod1 ,
476
- MetricsState : backendmetrics .NewMetricsState (),
477
- },
478
- & schedulingtypes.PodMetrics {
479
- Pod : outputPod2 ,
480
- MetricsState : backendmetrics .NewMetricsState (),
481
- },
482
- },
477
+ output : testInput ,
483
478
},
484
479
{
485
480
name : "SubsetFilter, namespace present filter not present — return all pods" ,
486
- metadata : map [string ]any {"envoy.lb.subset_hint" : map [string ]any {}},
487
- output : []schedulingtypes.Pod {
488
- & schedulingtypes.PodMetrics {
489
- Pod : outputPod1 ,
490
- MetricsState : backendmetrics .NewMetricsState (),
491
- },
492
- & schedulingtypes.PodMetrics {
493
- Pod : outputPod2 ,
494
- MetricsState : backendmetrics .NewMetricsState (),
495
- },
496
- },
481
+ metadata : map [string ]any {subsetHintNamespace : map [string ]any {}},
482
+ output : testInput ,
497
483
},
498
484
{
499
485
name : "SubsetFilter, filter present with empty list — return error" ,
500
486
metadata : makeFilterMetadata ([]any {}),
501
- output : []schedulingtypes. Pod {},
487
+ output : []backendmetrics. PodMetrics {},
502
488
},
503
489
{
504
490
name : "SubsetFilter, subset with one matching pod" ,
505
491
metadata : makeFilterMetadata ([]any {"10.0.0.1" }),
506
- output : []schedulingtypes.Pod {
507
- & schedulingtypes.PodMetrics {
508
- Pod : outputPod1 ,
509
- MetricsState : backendmetrics .NewMetricsState (),
492
+ output : []backendmetrics.PodMetrics {
493
+ & backendmetrics.FakePodMetrics {
494
+ Pod : pod1 ,
510
495
},
511
496
},
512
497
},
513
498
{
514
499
name : "SubsetFilter, subset with multiple matching pods" ,
515
500
metadata : makeFilterMetadata ([]any {"10.0.0.1" , "10.0.0.2" , "10.0.0.3" }),
516
- output : []schedulingtypes.Pod {
517
- & schedulingtypes.PodMetrics {
518
- Pod : outputPod1 ,
519
- MetricsState : backendmetrics .NewMetricsState (),
520
- },
521
- & schedulingtypes.PodMetrics {
522
- Pod : outputPod2 ,
523
- MetricsState : backendmetrics .NewMetricsState (),
524
- },
525
- },
501
+ output : testInput ,
526
502
},
527
503
{
528
504
name : "SubsetFilter, subset with no matching pods" ,
529
505
metadata : makeFilterMetadata ([]any {"10.0.0.3" }),
530
- output : []schedulingtypes. Pod {},
506
+ output : []backendmetrics. PodMetrics {},
531
507
},
532
508
}
533
509
534
- pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second , time .Second * 2 )
535
- ds := datastore .NewDatastore (t .Context (), pmf )
536
- for _ , testPod := range testInput {
537
- ds .PodUpdateOrAddIfNotExist (testPod )
538
- }
539
-
510
+ ds := & mockDatastore {pods : testInput }
540
511
for _ , test := range tests {
541
512
t .Run (test .name , func (t * testing.T ) {
542
513
director := NewDirectorWithConfig (ds , & mockScheduler {}, & mockSaturationDetector {}, NewConfig ())
543
514
544
515
got := director .getCandidatePodsForScheduling (context .Background (), test .metadata )
545
516
546
- diff := cmp .Diff (test .output , got , cmpopts .SortSlices (func (a , b schedulingtypes. Pod ) bool {
517
+ diff := cmp .Diff (test .output , got , cmpopts .SortSlices (func (a , b backendmetrics. PodMetrics ) bool {
547
518
return a .GetPod ().NamespacedName .String () < b .GetPod ().NamespacedName .String ()
548
519
}))
549
520
if diff != "" {
@@ -567,8 +538,8 @@ func TestRandomWeightedDraw(t *testing.T) {
567
538
model : & v1alpha2.InferenceObjective {
568
539
Spec : v1alpha2.InferenceObjectiveSpec {
569
540
TargetModels : []v1alpha2.TargetModel {
570
- {Name : "canary" , Weight : pointer ( 50 )},
571
- {Name : "v1" , Weight : pointer ( 50 )},
541
+ {Name : "canary" , Weight : ptr . To ( int32 ( 50 ) )},
542
+ {Name : "v1" , Weight : ptr . To ( int32 ( 50 ) )},
572
543
},
573
544
},
574
545
},
@@ -579,9 +550,9 @@ func TestRandomWeightedDraw(t *testing.T) {
579
550
model : & v1alpha2.InferenceObjective {
580
551
Spec : v1alpha2.InferenceObjectiveSpec {
581
552
TargetModels : []v1alpha2.TargetModel {
582
- {Name : "canary" , Weight : pointer ( 25 )},
583
- {Name : "v1.1" , Weight : pointer ( 55 )},
584
- {Name : "v1" , Weight : pointer ( 50 )},
553
+ {Name : "canary" , Weight : ptr . To ( int32 ( 25 ) )},
554
+ {Name : "v1.1" , Weight : ptr . To ( int32 ( 55 ) )},
555
+ {Name : "v1" , Weight : ptr . To ( int32 ( 50 ) )},
585
556
},
586
557
},
587
558
},
@@ -592,9 +563,9 @@ func TestRandomWeightedDraw(t *testing.T) {
592
563
model : & v1alpha2.InferenceObjective {
593
564
Spec : v1alpha2.InferenceObjectiveSpec {
594
565
TargetModels : []v1alpha2.TargetModel {
595
- {Name : "canary" , Weight : pointer ( 20 )},
596
- {Name : "v1.1" , Weight : pointer ( 20 )},
597
- {Name : "v1" , Weight : pointer ( 10 )},
566
+ {Name : "canary" , Weight : ptr . To ( int32 ( 20 ) )},
567
+ {Name : "v1.1" , Weight : ptr . To ( int32 ( 20 ) )},
568
+ {Name : "v1" , Weight : ptr . To ( int32 ( 10 ) )},
598
569
},
599
570
},
600
571
},
@@ -672,10 +643,6 @@ func TestGetRandomPod(t *testing.T) {
672
643
}
673
644
}
674
645
675
- func pointer (v int32 ) * int32 {
676
- return & v
677
- }
678
-
679
646
func TestDirector_HandleResponse (t * testing.T ) {
680
647
pr1 := newTestPostResponse ("pr1" )
681
648
0 commit comments