@@ -31,6 +31,7 @@ import (
3131 "k8s.io/apimachinery/pkg/runtime"
3232 "k8s.io/apimachinery/pkg/types"
3333 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
34+ "k8s.io/utils/ptr"
3435 "sigs.k8s.io/controller-runtime/pkg/client/fake"
3536
3637 v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
@@ -54,7 +55,7 @@ type mockSaturationDetector struct {
5455 isSaturated bool
5556}
5657
57- func (m * mockSaturationDetector ) IsSaturated (_ context.Context ) bool {
58+ func (m * mockSaturationDetector ) IsSaturated (_ context.Context , _ []backendmetrics. PodMetrics ) bool {
5859 return m .isSaturated
5960}
6061
@@ -67,6 +68,23 @@ func (m *mockScheduler) Schedule(_ context.Context, _ *schedulingtypes.LLMReques
6768 return m .scheduleResults , m .scheduleErr
6869}
6970
71+ type mockDatastore struct {
72+ pods []backendmetrics.PodMetrics
73+ }
74+
75+ func (ds * mockDatastore ) PoolGet () (* v1.InferencePool , error ) { return nil , nil }
76+ func (ds * mockDatastore ) ObjectiveGet (_ string ) * v1alpha2.InferenceObjective { return nil }
77+ func (ds * mockDatastore ) PodList (predicate func (backendmetrics.PodMetrics ) bool ) []backendmetrics.PodMetrics {
78+ res := []backendmetrics.PodMetrics {}
79+ for _ , pod := range ds .pods {
80+ if predicate (pod ) {
81+ res = append (res , pod )
82+ }
83+ }
84+
85+ return res
86+ }
87+
7088func TestDirector_HandleRequest (t * testing.T ) {
7189 ctx := logutil .NewTestLoggerIntoContext (context .Background ())
7290
@@ -442,119 +460,72 @@ func TestGetCandidatePodsForScheduling(t *testing.T) {
442460 }
443461 }
444462
445- testInput := []* corev1.Pod {
446- {
447- ObjectMeta : metav1.ObjectMeta {
448- Name : "pod1" ,
449- },
450- Status : corev1.PodStatus {
451- PodIP : "10.0.0.1" ,
452- },
453- },
454- {
455- ObjectMeta : metav1.ObjectMeta {
456- Name : "pod2" ,
457- },
458- Status : corev1.PodStatus {
459- PodIP : "10.0.0.2" ,
460- },
461- },
462- }
463-
464- outputPod1 := & backend.Pod {
463+ pod1 := & backend.Pod {
465464 NamespacedName : types.NamespacedName {Name : "pod1" },
466465 Address : "10.0.0.1" ,
467466 Labels : map [string ]string {},
468467 }
469468
470- outputPod2 := & backend.Pod {
469+ pod2 := & backend.Pod {
471470 NamespacedName : types.NamespacedName {Name : "pod2" },
472471 Address : "10.0.0.2" ,
473472 Labels : map [string ]string {},
474473 }
475474
475+ testInput := []backendmetrics.PodMetrics {
476+ & backendmetrics.FakePodMetrics {Pod : pod1 },
477+ & backendmetrics.FakePodMetrics {Pod : pod2 },
478+ }
479+
476480 tests := []struct {
477481 name string
478482 metadata map [string ]any
479- output []schedulingtypes. Pod
483+ output []backendmetrics. PodMetrics
480484 }{
481485 {
482486 name : "SubsetFilter, filter not present — return all pods" ,
483487 metadata : map [string ]any {},
484- output : []schedulingtypes.Pod {
485- & schedulingtypes.PodMetrics {
486- Pod : outputPod1 ,
487- MetricsState : backendmetrics .NewMetricsState (),
488- },
489- & schedulingtypes.PodMetrics {
490- Pod : outputPod2 ,
491- MetricsState : backendmetrics .NewMetricsState (),
492- },
493- },
488+ output : testInput ,
494489 },
495490 {
496491 name : "SubsetFilter, namespace present filter not present — return all pods" ,
497492 metadata : map [string ]any {metadata .SubsetFilterNamespace : map [string ]any {}},
498- output : []schedulingtypes.Pod {
499- & schedulingtypes.PodMetrics {
500- Pod : outputPod1 ,
501- MetricsState : backendmetrics .NewMetricsState (),
502- },
503- & schedulingtypes.PodMetrics {
504- Pod : outputPod2 ,
505- MetricsState : backendmetrics .NewMetricsState (),
506- },
507- },
493+ output : testInput ,
508494 },
509495 {
510496 name : "SubsetFilter, filter present with empty list — return error" ,
511497 metadata : makeFilterMetadata ([]any {}),
512- output : []schedulingtypes. Pod {},
498+ output : []backendmetrics. PodMetrics {},
513499 },
514500 {
515501 name : "SubsetFilter, subset with one matching pod" ,
516502 metadata : makeFilterMetadata ([]any {"10.0.0.1" }),
517- output : []schedulingtypes.Pod {
518- & schedulingtypes.PodMetrics {
519- Pod : outputPod1 ,
520- MetricsState : backendmetrics .NewMetricsState (),
503+ output : []backendmetrics.PodMetrics {
504+ & backendmetrics.FakePodMetrics {
505+ Pod : pod1 ,
521506 },
522507 },
523508 },
524509 {
525510 name : "SubsetFilter, subset with multiple matching pods" ,
526511 metadata : makeFilterMetadata ([]any {"10.0.0.1" , "10.0.0.2" , "10.0.0.3" }),
527- output : []schedulingtypes.Pod {
528- & schedulingtypes.PodMetrics {
529- Pod : outputPod1 ,
530- MetricsState : backendmetrics .NewMetricsState (),
531- },
532- & schedulingtypes.PodMetrics {
533- Pod : outputPod2 ,
534- MetricsState : backendmetrics .NewMetricsState (),
535- },
536- },
512+ output : testInput ,
537513 },
538514 {
539515 name : "SubsetFilter, subset with no matching pods" ,
540516 metadata : makeFilterMetadata ([]any {"10.0.0.3" }),
541- output : []schedulingtypes. Pod {},
517+ output : []backendmetrics. PodMetrics {},
542518 },
543519 }
544520
545- pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second , time .Second * 2 )
546- ds := datastore .NewDatastore (t .Context (), pmf )
547- for _ , testPod := range testInput {
548- ds .PodUpdateOrAddIfNotExist (testPod )
549- }
550-
521+ ds := & mockDatastore {pods : testInput }
551522 for _ , test := range tests {
552523 t .Run (test .name , func (t * testing.T ) {
553524 director := NewDirectorWithConfig (ds , & mockScheduler {}, & mockSaturationDetector {}, NewConfig ())
554525
555526 got := director .getCandidatePodsForScheduling (context .Background (), test .metadata )
556527
557- diff := cmp .Diff (test .output , got , cmpopts .SortSlices (func (a , b schedulingtypes. Pod ) bool {
528+ diff := cmp .Diff (test .output , got , cmpopts .SortSlices (func (a , b backendmetrics. PodMetrics ) bool {
558529 return a .GetPod ().NamespacedName .String () < b .GetPod ().NamespacedName .String ()
559530 }))
560531 if diff != "" {
@@ -578,8 +549,8 @@ func TestRandomWeightedDraw(t *testing.T) {
578549 model : & v1alpha2.InferenceObjective {
579550 Spec : v1alpha2.InferenceObjectiveSpec {
580551 TargetModels : []v1alpha2.TargetModel {
581- {Name : "canary" , Weight : pointer ( 50 )},
582- {Name : "v1" , Weight : pointer ( 50 )},
552+ {Name : "canary" , Weight : ptr . To ( int32 ( 50 ) )},
553+ {Name : "v1" , Weight : ptr . To ( int32 ( 50 ) )},
583554 },
584555 },
585556 },
@@ -590,9 +561,9 @@ func TestRandomWeightedDraw(t *testing.T) {
590561 model : & v1alpha2.InferenceObjective {
591562 Spec : v1alpha2.InferenceObjectiveSpec {
592563 TargetModels : []v1alpha2.TargetModel {
593- {Name : "canary" , Weight : pointer ( 25 )},
594- {Name : "v1.1" , Weight : pointer ( 55 )},
595- {Name : "v1" , Weight : pointer ( 50 )},
564+ {Name : "canary" , Weight : ptr . To ( int32 ( 25 ) )},
565+ {Name : "v1.1" , Weight : ptr . To ( int32 ( 55 ) )},
566+ {Name : "v1" , Weight : ptr . To ( int32 ( 50 ) )},
596567 },
597568 },
598569 },
@@ -603,9 +574,9 @@ func TestRandomWeightedDraw(t *testing.T) {
603574 model : & v1alpha2.InferenceObjective {
604575 Spec : v1alpha2.InferenceObjectiveSpec {
605576 TargetModels : []v1alpha2.TargetModel {
606- {Name : "canary" , Weight : pointer ( 20 )},
607- {Name : "v1.1" , Weight : pointer ( 20 )},
608- {Name : "v1" , Weight : pointer ( 10 )},
577+ {Name : "canary" , Weight : ptr . To ( int32 ( 20 ) )},
578+ {Name : "v1.1" , Weight : ptr . To ( int32 ( 20 ) )},
579+ {Name : "v1" , Weight : ptr . To ( int32 ( 10 ) )},
609580 },
610581 },
611582 },
@@ -683,10 +654,6 @@ func TestGetRandomPod(t *testing.T) {
683654 }
684655}
685656
686- func pointer (v int32 ) * int32 {
687- return & v
688- }
689-
690657func TestDirector_HandleResponse (t * testing.T ) {
691658 pr1 := newTestPostResponse ("pr1" )
692659
0 commit comments