Skip to content

Commit 4c5aa2a

Browse files
authored
create pods during integration tests (#431)
* create pods during integration tests Signed-off-by: Kuromesi <[email protected]> * fix Signed-off-by: Kuromesi <[email protected]> --------- Signed-off-by: Kuromesi <[email protected]>
1 parent 14afcd9 commit 4c5aa2a

File tree

3 files changed

+68
-23
lines changed

3 files changed

+68
-23
lines changed

pkg/epp/test/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func GenerateRequest(logger logr.Logger, prompt, model string) *extProcPb.Proces
114114
}
115115

116116
func FakePodMetrics(index int, metrics datastore.Metrics) *datastore.PodMetrics {
117-
address := fmt.Sprintf("address-%v", index)
117+
address := fmt.Sprintf("192.168.1.%d", index+1)
118118
pod := datastore.PodMetrics{
119119
Pod: datastore.Pod{
120-
NamespacedName: types.NamespacedName{Name: fmt.Sprintf("pod-%v", index)},
120+
NamespacedName: types.NamespacedName{Name: fmt.Sprintf("pod-%v", index), Namespace: "default"},
121121
Address: address,
122122
},
123123
Metrics: metrics,

pkg/epp/util/testing/wrappers.go

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ func MakePod(podName string) *PodWrapper {
4040
}
4141
}
4242

43+
// Complete sets necessary fields for a Pod to make it not denied by the apiserver
44+
func (p *PodWrapper) Complete() *PodWrapper {
45+
if p.Pod.Namespace == "" {
46+
p.Namespace("default")
47+
}
48+
p.Spec.Containers = []corev1.Container{
49+
{
50+
Name: "mock-vllm",
51+
Image: "mock-vllm:latest",
52+
},
53+
}
54+
return p
55+
}
56+
4357
func (p *PodWrapper) Namespace(ns string) *PodWrapper {
4458
p.ObjectMeta.Namespace = ns
4559
return p

test/integration/hermetic_test.go

+52-21
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
112112
{
113113
Header: &configPb.HeaderValue{
114114
Key: runserver.DefaultDestinationEndpointHintKey,
115-
RawValue: []byte("address-1:8000"),
115+
RawValue: []byte("192.168.1.2:8000"),
116116
},
117117
},
118118
{
@@ -122,7 +122,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
122122
},
123123
},
124124
},
125-
wantMetadata: makeMetadata("address-1:8000"),
125+
wantMetadata: makeMetadata("192.168.1.2:8000"),
126126
wantBody: []byte("{\"max_tokens\":100,\"model\":\"my-model-12345\",\"prompt\":\"test1\",\"temperature\":0}"),
127127
wantMetrics: `
128128
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
@@ -165,7 +165,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
165165
{
166166
Header: &configPb.HeaderValue{
167167
Key: runserver.DefaultDestinationEndpointHintKey,
168-
RawValue: []byte("address-1:8000"),
168+
RawValue: []byte("192.168.1.2:8000"),
169169
},
170170
},
171171
{
@@ -175,7 +175,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
175175
},
176176
},
177177
},
178-
wantMetadata: makeMetadata("address-1:8000"),
178+
wantMetadata: makeMetadata("192.168.1.2:8000"),
179179
wantBody: []byte("{\"max_tokens\":100,\"model\":\"sql-lora-1fdg2\",\"prompt\":\"test2\",\"temperature\":0}"),
180180
wantMetrics: `
181181
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
@@ -219,7 +219,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
219219
{
220220
Header: &configPb.HeaderValue{
221221
Key: runserver.DefaultDestinationEndpointHintKey,
222-
RawValue: []byte("address-2:8000"),
222+
RawValue: []byte("192.168.1.3:8000"),
223223
},
224224
},
225225
{
@@ -229,7 +229,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
229229
},
230230
},
231231
},
232-
wantMetadata: makeMetadata("address-2:8000"),
232+
wantMetadata: makeMetadata("192.168.1.3:8000"),
233233
wantBody: []byte("{\"max_tokens\":100,\"model\":\"sql-lora-1fdg2\",\"prompt\":\"test3\",\"temperature\":0}"),
234234
wantMetrics: `
235235
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
@@ -316,7 +316,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
316316
{
317317
Header: &configPb.HeaderValue{
318318
Key: runserver.DefaultDestinationEndpointHintKey,
319-
RawValue: []byte("address-0:8000"),
319+
RawValue: []byte("192.168.1.1:8000"),
320320
},
321321
},
322322
{
@@ -326,7 +326,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
326326
},
327327
},
328328
},
329-
wantMetadata: makeMetadata("address-0:8000"),
329+
wantMetadata: makeMetadata("192.168.1.1:8000"),
330330
wantBody: []byte("{\"max_tokens\":100,\"model\":\"sql-lora-1fdg3\",\"prompt\":\"test5\",\"temperature\":0}"),
331331
wantMetrics: `
332332
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
@@ -343,7 +343,7 @@ func TestKubeInferenceModelRequest(t *testing.T) {
343343

344344
for _, test := range tests {
345345
t.Run(test.name, func(t *testing.T) {
346-
client, cleanup := setUpHermeticServer(test.pods)
346+
client, cleanup := setUpHermeticServer(t, test.pods)
347347
t.Cleanup(cleanup)
348348
want := &extProcPb.ProcessingResponse{
349349
Response: &extProcPb.ProcessingResponse_RequestBody{
@@ -389,31 +389,52 @@ func TestKubeInferenceModelRequest(t *testing.T) {
389389
}
390390
}
391391

392-
func setUpHermeticServer(podMetrics []*datastore.PodMetrics) (client extProcPb.ExternalProcessor_ProcessClient, cleanup func()) {
392+
func setUpHermeticServer(t *testing.T, podMetrics []*datastore.PodMetrics) (client extProcPb.ExternalProcessor_ProcessClient, cleanup func()) {
393393
pms := make(map[types.NamespacedName]*datastore.PodMetrics)
394394
for _, pm := range podMetrics {
395395
pms[pm.NamespacedName] = pm
396396
}
397397
pmc := &backend.FakePodMetricsClient{Res: pms}
398398

399399
serverCtx, stopServer := context.WithCancel(context.Background())
400-
go func() {
401-
serverRunner.Datastore.PodDeleteAll()
402-
for _, pm := range podMetrics {
403-
pod := utiltesting.MakePod(pm.NamespacedName.Name).
404-
Namespace(pm.NamespacedName.Namespace).
405-
ReadyCondition().
406-
IP(pm.Address).
407-
ObjRef()
408-
serverRunner.Datastore.PodUpdateOrAddIfNotExist(pod)
409-
serverRunner.Datastore.PodUpdateMetricsIfExist(pm.NamespacedName, &pm.Metrics)
400+
401+
// TODO: this should be consistent with the inference pool
402+
podLabels := map[string]string{
403+
"app": "vllm-llama2-7b-pool",
404+
}
405+
406+
for _, pm := range podMetrics {
407+
pod := utiltesting.MakePod(pm.NamespacedName.Name).
408+
Namespace(pm.NamespacedName.Namespace).
409+
ReadyCondition().
410+
Labels(podLabels).
411+
IP(pm.Address).
412+
Complete().
413+
ObjRef()
414+
415+
copy := pod.DeepCopy()
416+
if err := k8sClient.Create(context.Background(), copy); err != nil {
417+
logutil.Fatal(logger, err, "Failed to create pod", "pod", pm.NamespacedName)
410418
}
411-
serverRunner.Provider = backend.NewProvider(pmc, serverRunner.Datastore)
419+
420+
// since no pod controllers deployed in fake environment, we manually update pod status
421+
copy.Status = pod.Status
422+
if err := k8sClient.Status().Update(context.Background(), copy); err != nil {
423+
logutil.Fatal(logger, err, "Failed to update pod status", "pod", pm.NamespacedName)
424+
}
425+
}
426+
serverRunner.Provider = backend.NewProvider(pmc, serverRunner.Datastore)
427+
go func() {
412428
if err := serverRunner.AsRunnable(logger.WithName("ext-proc")).Start(serverCtx); err != nil {
413429
logutil.Fatal(logger, err, "Failed to start ext-proc server")
414430
}
415431
}()
416432

433+
// check if all pods are synced to datastore
434+
assert.EventuallyWithT(t, func(t *assert.CollectT) {
435+
assert.Len(t, serverRunner.Datastore.PodGetAll(), len(podMetrics), "Datastore not synced")
436+
}, 10*time.Second, time.Second)
437+
417438
address := fmt.Sprintf("localhost:%v", port)
418439
// Create a grpc connection
419440
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -430,6 +451,16 @@ func setUpHermeticServer(podMetrics []*datastore.PodMetrics) (client extProcPb.E
430451
cancel()
431452
conn.Close()
432453
stopServer()
454+
455+
// clear created pods
456+
for _, pm := range podMetrics {
457+
pod := utiltesting.MakePod(pm.NamespacedName.Name).
458+
Namespace(pm.NamespacedName.Namespace).Complete().ObjRef()
459+
460+
if err := k8sClient.Delete(context.Background(), pod); err != nil {
461+
logutil.Fatal(logger, err, "Failed to delete pod", "pod", pm.NamespacedName)
462+
}
463+
}
433464
// wait a little until the goroutines actually exit
434465
time.Sleep(5 * time.Second)
435466
}

0 commit comments

Comments
 (0)