Skip to content

Commit 5c91cc2

Browse files
committed
director: delegate candidate resolution
Refactors the Director to use the injected PodLocator interface instead of the private getCandidatePodsForScheduling method. This prepares the Director for lazy resolution without changing current behavior.
1 parent 1a55876 commit 5c91cc2

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

pkg/epp/flowcontrol/contracts/dependencies.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121

2222
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
23-
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
2423
)
2524

2625
// PodLocator defines the contract for a component that resolves the set of candidate pods for a request based on its
@@ -30,7 +29,7 @@ import (
3029
// enabling support for "Scale-from-Zero" scenarios where pods may not exist when the request is first enqueued.
3130
type PodLocator interface {
3231
// Locate returns a list of pod metrics that match the criteria defined in the request metadata.
33-
Locate(ctx context.Context, requestMetadata map[string]any) []backendmetrics.PodMetrics
32+
Locate(ctx context.Context, requestMetadata map[string]any) []metrics.PodMetrics
3433
}
3534

3635
// SaturationDetector defines the contract for a component that provides real-time load signals to the

pkg/epp/requestcontrol/director_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -651,41 +651,42 @@ func TestDirector_HandleRequest(t *testing.T) {
651651
ds.PodUpdateOrAddIfNotExist(testPod)
652652
}
653653

654-
for _, test := range tests {
655-
t.Run(test.name, func(t *testing.T) {
656-
mockSched := &mockScheduler{}
657-
if test.schedulerMockSetup != nil {
658-
test.schedulerMockSetup(mockSched)
659-
}
660-
config := NewConfig()
661-
if test.prepareDataPlugin != nil {
662-
config = config.WithPrepareDataPlugins(test.prepareDataPlugin)
663-
}
664-
config = config.WithAdmissionPlugins(newMockAdmissionPlugin("test-admit-plugin", test.admitRequestDenialError))
665-
666-
locator := NewCachedPodLocator(context.Background(), NewDatastorePodLocator(ds), time.Minute)
667-
director := NewDirectorWithConfig(ds, mockSched, test.mockAdmissionController, locator, config)
668-
if test.name == "successful request with model rewrite" {
669-
mockDs := &mockDatastore{
670-
pods: ds.PodList(datastore.AllPodsPredicate),
671-
rewrites: []*v1alpha2.InferenceModelRewrite{rewrite},
672-
}
673-
director.datastore = mockDs
674-
director.podLocator = NewCachedPodLocator(context.Background(), NewDatastorePodLocator(mockDs), time.Minute)
654+
for _, test := range tests {
655+
t.Run(test.name, func(t *testing.T) {
656+
mockSched := &mockScheduler{}
657+
if test.schedulerMockSetup != nil {
658+
test.schedulerMockSetup(mockSched)
659+
}
660+
config := NewConfig()
661+
if test.prepareDataPlugin != nil {
662+
config = config.WithPrepareDataPlugins(test.prepareDataPlugin)
663+
}
664+
config = config.WithAdmissionPlugins(newMockAdmissionPlugin("test-admit-plugin", test.admitRequestDenialError))
665+
666+
locator := NewCachedPodLocator(context.Background(), NewDatastorePodLocator(ds), time.Minute)
667+
director := NewDirectorWithConfig(ds, mockSched, test.mockAdmissionController, locator, config)
668+
if test.name == "successful request with model rewrite" {
669+
mockDs := &mockDatastore{
670+
pods: ds.PodList(datastore.AllPodsPredicate),
671+
rewrites: []*v1alpha2.InferenceModelRewrite{rewrite},
675672
}
676-
reqCtx := &handlers.RequestContext{
677-
Request: &handlers.Request{
678-
// Create a copy of the map for each test run to avoid mutation issues.
679-
Body: make(map[string]any),
680-
Headers: map[string]string{
681-
requtil.RequestIdHeaderKey: "test-req-id-" + test.name, // Ensure a default request ID
682-
},
673+
director.datastore = mockDs
674+
director.podLocator = NewCachedPodLocator(context.Background(), NewDatastorePodLocator(mockDs), time.Minute)
675+
}
676+
677+
reqCtx := &handlers.RequestContext{
678+
Request: &handlers.Request{
679+
// Create a copy of the map for each test run to avoid mutation issues.
680+
Body: make(map[string]any),
681+
Headers: map[string]string{
682+
requtil.RequestIdHeaderKey: "test-req-id-" + test.name, // Ensure a default request ID
683683
},
684-
ObjectiveKey: test.inferenceObjectiveName,
685-
TargetModelName: test.initialTargetModelName,
686-
}
687-
// Deep copy the body map.
688-
maps.Copy(reqCtx.Request.Body, test.reqBodyMap)
684+
},
685+
ObjectiveKey: test.inferenceObjectiveName,
686+
TargetModelName: test.initialTargetModelName,
687+
}
688+
// Deep copy the body map.
689+
maps.Copy(reqCtx.Request.Body, test.reqBodyMap)
689690

690691
returnedReqCtx, err := director.HandleRequest(ctx, reqCtx)
691692

@@ -708,13 +709,12 @@ func TestDirector_HandleRequest(t *testing.T) {
708709
assert.Equal(t, test.wantReqCtx.TargetEndpoint, returnedReqCtx.TargetEndpoint, "reqCtx.TargetEndpoint mismatch")
709710
}
710711

711-
if test.wantMutatedBodyModel != "" {
712-
assert.NotNil(t, returnedReqCtx.Request.Body, "Expected mutated body, but reqCtx.Request.Body is nil")
713-
assert.Equal(t, test.wantMutatedBodyModel, returnedReqCtx.Request.Body["model"],
714-
"Mutated reqCtx.Request.Body model mismatch")
715-
}
716-
})
717-
}
712+
if test.wantMutatedBodyModel != "" {
713+
assert.NotNil(t, returnedReqCtx.Request.Body, "Expected mutated body, but reqCtx.Request.Body is nil")
714+
assert.Equal(t, test.wantMutatedBodyModel, returnedReqCtx.Request.Body["model"],
715+
"Mutated reqCtx.Request.Body model mismatch")
716+
}
717+
})
718718
}
719719
}
720720

0 commit comments

Comments
 (0)