@@ -26,7 +26,6 @@ import (
2626 "time"
2727
2828 "github.com/google/go-cmp/cmp"
29- "github.com/google/go-cmp/cmp/cmpopts"
3029 "github.com/stretchr/testify/assert"
3130 corev1 "k8s.io/api/core/v1"
3231 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -42,7 +41,6 @@ import (
4241 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datalayer"
4342 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
4443 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/handlers"
45- "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metadata"
4644 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
4745 schedulingtypes "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
4846 errutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/error"
@@ -659,9 +657,16 @@ func TestDirector_HandleRequest(t *testing.T) {
659657 config = config .WithPrepareDataPlugins (test .prepareDataPlugin )
660658 }
661659 config = config .WithAdmissionPlugins (newMockAdmissionPlugin ("test-admit-plugin" , test .admitRequestDenialError ))
662- director := NewDirectorWithConfig (ds , mockSched , test .mockAdmissionController , config )
660+
661+ locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (ds ), time .Minute )
662+ director := NewDirectorWithConfig (ds , mockSched , test .mockAdmissionController , locator , config )
663663 if test .name == "successful request with model rewrite" {
664- director .datastore = & mockDatastore {pods : ds .PodList (datastore .AllPodsPredicate ), rewrites : []* v1alpha2.InferenceModelRewrite {rewrite }}
664+ mockDs := & mockDatastore {
665+ pods : ds .PodList (datastore .AllPodsPredicate ),
666+ rewrites : []* v1alpha2.InferenceModelRewrite {rewrite },
667+ }
668+ director .datastore = mockDs
669+ director .podLocator = NewCachedPodLocator (context .Background (), NewDatastorePodLocator (mockDs ), time .Minute )
665670 }
666671
667672 reqCtx := & handlers.RequestContext {
@@ -708,91 +713,6 @@ func TestDirector_HandleRequest(t *testing.T) {
708713 }
709714}
710715
711- // TestGetCandidatePodsForScheduling is testing getCandidatePodsForScheduling and more specifically the functionality of SubsetFilter.
712- func TestGetCandidatePodsForScheduling (t * testing.T ) {
713- var makeFilterMetadata = func (data []any ) map [string ]any {
714- return map [string ]any {
715- metadata .SubsetFilterNamespace : map [string ]any {
716- metadata .SubsetFilterKey : data ,
717- },
718- }
719- }
720-
721- pod1 := & backend.Pod {
722- NamespacedName : types.NamespacedName {Name : "pod1" },
723- Address : "10.0.0.1" ,
724- Labels : map [string ]string {},
725- }
726-
727- pod2 := & backend.Pod {
728- NamespacedName : types.NamespacedName {Name : "pod2" },
729- Address : "10.0.0.2" ,
730- Labels : map [string ]string {},
731- }
732-
733- testInput := []backendmetrics.PodMetrics {
734- & backendmetrics.FakePodMetrics {Pod : pod1 },
735- & backendmetrics.FakePodMetrics {Pod : pod2 },
736- }
737-
738- tests := []struct {
739- name string
740- metadata map [string ]any
741- output []backendmetrics.PodMetrics
742- }{
743- {
744- name : "SubsetFilter, filter not present — return all pods" ,
745- metadata : map [string ]any {},
746- output : testInput ,
747- },
748- {
749- name : "SubsetFilter, namespace present filter not present — return all pods" ,
750- metadata : map [string ]any {metadata .SubsetFilterNamespace : map [string ]any {}},
751- output : testInput ,
752- },
753- {
754- name : "SubsetFilter, filter present with empty list — return error" ,
755- metadata : makeFilterMetadata ([]any {}),
756- output : []backendmetrics.PodMetrics {},
757- },
758- {
759- name : "SubsetFilter, subset with one matching pod" ,
760- metadata : makeFilterMetadata ([]any {"10.0.0.1" }),
761- output : []backendmetrics.PodMetrics {
762- & backendmetrics.FakePodMetrics {
763- Pod : pod1 ,
764- },
765- },
766- },
767- {
768- name : "SubsetFilter, subset with multiple matching pods" ,
769- metadata : makeFilterMetadata ([]any {"10.0.0.1" , "10.0.0.2" , "10.0.0.3" }),
770- output : testInput ,
771- },
772- {
773- name : "SubsetFilter, subset with no matching pods" ,
774- metadata : makeFilterMetadata ([]any {"10.0.0.3" }),
775- output : []backendmetrics.PodMetrics {},
776- },
777- }
778-
779- ds := & mockDatastore {pods : testInput }
780- for _ , test := range tests {
781- t .Run (test .name , func (t * testing.T ) {
782- director := NewDirectorWithConfig (ds , & mockScheduler {}, & mockAdmissionController {}, NewConfig ())
783-
784- got := director .getCandidatePodsForScheduling (context .Background (), test .metadata )
785-
786- diff := cmp .Diff (test .output , got , cmpopts .SortSlices (func (a , b backendmetrics.PodMetrics ) bool {
787- return a .GetPod ().NamespacedName .String () < b .GetPod ().NamespacedName .String ()
788- }))
789- if diff != "" {
790- t .Errorf ("Unexpected output (-want +got): %v" , diff )
791- }
792- })
793- }
794- }
795-
796716func TestGetRandomPod (t * testing.T ) {
797717 tests := []struct {
798718 name string
@@ -1028,7 +948,8 @@ func TestDirector_ApplyWeightedModelRewrite(t *testing.T) {
1028948 for _ , test := range tests {
1029949 t .Run (test .name , func (t * testing.T ) {
1030950 mockDs := & mockDatastore {rewrites : test .rewrites }
1031- director := NewDirectorWithConfig (mockDs , & mockScheduler {}, & mockAdmissionController {}, NewConfig ())
951+ locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (mockDs ), time .Minute )
952+ director := NewDirectorWithConfig (mockDs , & mockScheduler {}, & mockAdmissionController {}, locator , NewConfig ())
1032953
1033954 reqCtx := & handlers.RequestContext {
1034955 IncomingModelName : test .incomingModel ,
@@ -1128,7 +1049,14 @@ func TestDirector_HandleResponseReceived(t *testing.T) {
11281049 ctx := logutil .NewTestLoggerIntoContext (context .Background ())
11291050 ds := datastore .NewDatastore (t .Context (), nil , 0 )
11301051 mockSched := & mockScheduler {}
1131- director := NewDirectorWithConfig (ds , mockSched , & mockAdmissionController {}, NewConfig ().WithResponseReceivedPlugins (pr1 ))
1052+ locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (ds ), time .Minute )
1053+ director := NewDirectorWithConfig (
1054+ ds ,
1055+ mockSched ,
1056+ & mockAdmissionController {},
1057+ locator ,
1058+ NewConfig ().WithResponseReceivedPlugins (pr1 ),
1059+ )
11321060
11331061 reqCtx := & handlers.RequestContext {
11341062 Request : & handlers.Request {
@@ -1165,7 +1093,8 @@ func TestDirector_HandleResponseStreaming(t *testing.T) {
11651093 ctx := logutil .NewTestLoggerIntoContext (context .Background ())
11661094 ds := datastore .NewDatastore (t .Context (), nil , 0 )
11671095 mockSched := & mockScheduler {}
1168- director := NewDirectorWithConfig (ds , mockSched , nil , NewConfig ().WithResponseStreamingPlugins (ps1 ))
1096+ locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (ds ), time .Minute )
1097+ director := NewDirectorWithConfig (ds , mockSched , nil , locator , NewConfig ().WithResponseStreamingPlugins (ps1 ))
11691098
11701099 reqCtx := & handlers.RequestContext {
11711100 Request : & handlers.Request {
@@ -1201,7 +1130,8 @@ func TestDirector_HandleResponseComplete(t *testing.T) {
12011130 ctx := logutil .NewTestLoggerIntoContext (context .Background ())
12021131 ds := datastore .NewDatastore (t .Context (), nil , 0 )
12031132 mockSched := & mockScheduler {}
1204- director := NewDirectorWithConfig (ds , mockSched , nil , NewConfig ().WithResponseCompletePlugins (pc1 ))
1133+ locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (ds ), time .Minute )
1134+ director := NewDirectorWithConfig (ds , mockSched , nil , locator , NewConfig ().WithResponseCompletePlugins (pc1 ))
12051135
12061136 reqCtx := & handlers.RequestContext {
12071137 Request : & handlers.Request {
0 commit comments