@@ -19,6 +19,7 @@ package requestcontrol
19
19
import (
20
20
"context"
21
21
"errors"
22
+ "fmt"
22
23
"testing"
23
24
"time"
24
25
@@ -109,26 +110,29 @@ func TestDirector_HandleRequest(t *testing.T) {
109
110
},
110
111
}
111
112
112
- // Pod setup
113
- testPod := & corev1.Pod {
114
- ObjectMeta : metav1.ObjectMeta {
115
- Name : "pod1" ,
116
- Namespace : "default" ,
117
- Labels : map [string ]string {"app" : "inference" },
118
- },
119
- Status : corev1.PodStatus {
120
- PodIP : "192.168.1.100" ,
121
- Phase : corev1 .PodRunning ,
122
- Conditions : []corev1.PodCondition {{Type : corev1 .PodReady , Status : corev1 .ConditionTrue }},
123
- },
124
- }
125
113
scheme := runtime .NewScheme ()
126
114
_ = clientgoscheme .AddToScheme (scheme )
127
115
fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
128
116
if err := ds .PoolSet (ctx , fakeClient , pool ); err != nil {
129
117
t .Fatalf ("Error while setting inference pool: %v" , err )
130
118
}
131
- ds .PodUpdateOrAddIfNotExist (testPod )
119
+
120
+ for i := range 5 {
121
+ // Pod setup
122
+ testPod := & corev1.Pod {
123
+ ObjectMeta : metav1.ObjectMeta {
124
+ Name : fmt .Sprintf ("pod%v" , i + 1 ),
125
+ Namespace : "default" ,
126
+ Labels : map [string ]string {"app" : "inference" },
127
+ },
128
+ Status : corev1.PodStatus {
129
+ PodIP : fmt .Sprintf ("192.168.%v.100" , i + 1 ),
130
+ Phase : corev1 .PodRunning ,
131
+ Conditions : []corev1.PodCondition {{Type : corev1 .PodReady , Status : corev1 .ConditionTrue }},
132
+ },
133
+ }
134
+ ds .PodUpdateOrAddIfNotExist (testPod )
135
+ }
132
136
133
137
defaultSuccessfulScheduleResults := & schedulingtypes.SchedulingResult {
134
138
ProfileResults : map [string ]* schedulingtypes.ProfileRunResult {
@@ -142,6 +146,22 @@ func TestDirector_HandleRequest(t *testing.T) {
142
146
},
143
147
},
144
148
},
149
+ & schedulingtypes.ScoredPod {
150
+ Pod : & schedulingtypes.PodMetrics {
151
+ Pod : & backend.Pod {
152
+ Address : "192.168.2.100" ,
153
+ NamespacedName : k8stypes.NamespacedName {Name : "pod2" , Namespace : "default" },
154
+ },
155
+ },
156
+ },
157
+ & schedulingtypes.ScoredPod {
158
+ Pod : & schedulingtypes.PodMetrics {
159
+ Pod : & backend.Pod {
160
+ Address : "192.168.4.100" ,
161
+ NamespacedName : k8stypes.NamespacedName {Name : "pod4" , Namespace : "default" },
162
+ },
163
+ },
164
+ },
145
165
},
146
166
},
147
167
},
@@ -170,11 +190,21 @@ func TestDirector_HandleRequest(t *testing.T) {
170
190
wantReqCtx : & handlers.RequestContext {
171
191
Model : model ,
172
192
ResolvedTargetModel : model ,
173
- TargetPod : & backend.Pod {
174
- NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
175
- Address : "192.168.1.100" ,
193
+ TargetPods : []* backend.Pod {
194
+ {
195
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
196
+ Address : "192.168.1.100" ,
197
+ },
198
+ {
199
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod2" },
200
+ Address : "192.168.2.100" ,
201
+ },
202
+ {
203
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod4" },
204
+ Address : "192.168.4.100" ,
205
+ },
176
206
},
177
- TargetEndpoint : "192.168.1.100:8000" ,
207
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
178
208
},
179
209
wantMutatedBodyModel : model ,
180
210
},
@@ -195,11 +225,21 @@ func TestDirector_HandleRequest(t *testing.T) {
195
225
wantReqCtx : & handlers.RequestContext {
196
226
Model : model ,
197
227
ResolvedTargetModel : model ,
198
- TargetPod : & backend.Pod {
199
- NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
200
- Address : "192.168.1.100" ,
228
+ TargetPods : []* backend.Pod {
229
+ {
230
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
231
+ Address : "192.168.1.100" ,
232
+ },
233
+ {
234
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod2" },
235
+ Address : "192.168.2.100" ,
236
+ },
237
+ {
238
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod4" },
239
+ Address : "192.168.4.100" ,
240
+ },
201
241
},
202
- TargetEndpoint : "192.168.1.100:8000" ,
242
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
203
243
},
204
244
wantMutatedBodyModel : model ,
205
245
},
@@ -224,11 +264,21 @@ func TestDirector_HandleRequest(t *testing.T) {
224
264
wantReqCtx : & handlers.RequestContext {
225
265
Model : model ,
226
266
ResolvedTargetModel : model ,
227
- TargetPod : & backend.Pod {
228
- NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
229
- Address : "192.168.1.100" ,
267
+ TargetPods : []* backend.Pod {
268
+ {
269
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
270
+ Address : "192.168.1.100" ,
271
+ },
272
+ {
273
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod2" },
274
+ Address : "192.168.2.100" ,
275
+ },
276
+ {
277
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod4" },
278
+ Address : "192.168.4.100" ,
279
+ },
230
280
},
231
- TargetEndpoint : "192.168.1.100:8000" ,
281
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
232
282
},
233
283
wantMutatedBodyModel : model ,
234
284
},
@@ -245,11 +295,21 @@ func TestDirector_HandleRequest(t *testing.T) {
245
295
wantReqCtx : & handlers.RequestContext {
246
296
Model : modelSheddable ,
247
297
ResolvedTargetModel : modelSheddable ,
248
- TargetPod : & backend.Pod {
249
- NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
250
- Address : "192.168.1.100" ,
298
+ TargetPods : []* backend.Pod {
299
+ {
300
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
301
+ Address : "192.168.1.100" ,
302
+ },
303
+ {
304
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod2" },
305
+ Address : "192.168.2.100" ,
306
+ },
307
+ {
308
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod4" },
309
+ Address : "192.168.4.100" ,
310
+ },
251
311
},
252
- TargetEndpoint : "192.168.1.100:8000" ,
312
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
253
313
},
254
314
wantMutatedBodyModel : modelSheddable ,
255
315
},
@@ -266,11 +326,21 @@ func TestDirector_HandleRequest(t *testing.T) {
266
326
wantReqCtx : & handlers.RequestContext {
267
327
Model : modelWithResolvedTarget ,
268
328
ResolvedTargetModel : "resolved-target-model-A" ,
269
- TargetPod : & backend.Pod {
270
- NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
271
- Address : "192.168.1.100" ,
329
+ TargetPods : []* backend.Pod {
330
+ {
331
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
332
+ Address : "192.168.1.100" ,
333
+ },
334
+ {
335
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod2" },
336
+ Address : "192.168.2.100" ,
337
+ },
338
+ {
339
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod4" },
340
+ Address : "192.168.4.100" ,
341
+ },
272
342
},
273
- TargetEndpoint : "192.168.1.100:8000" ,
343
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
274
344
},
275
345
wantMutatedBodyModel : "resolved-target-model-A" ,
276
346
},
@@ -282,11 +352,21 @@ func TestDirector_HandleRequest(t *testing.T) {
282
352
wantReqCtx : & handlers.RequestContext {
283
353
Model : "food-review-1" ,
284
354
ResolvedTargetModel : "food-review-1" ,
285
- TargetPod : & backend.Pod {
286
- NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
287
- Address : "192.168.1.100" ,
355
+ TargetPods : []* backend.Pod {
356
+ {
357
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod1" },
358
+ Address : "192.168.1.100" ,
359
+ },
360
+ {
361
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod2" },
362
+ Address : "192.168.2.100" ,
363
+ },
364
+ {
365
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "pod4" },
366
+ Address : "192.168.4.100" ,
367
+ },
288
368
},
289
- TargetEndpoint : "192.168.1.100:8000" ,
369
+ TargetEndpoint : "192.168.1.100:8000,192.168.2.100:8000,192.168.4.100:8000 " ,
290
370
},
291
371
wantMutatedBodyModel : "food-review-1" ,
292
372
reqBodyMap : map [string ]any {
@@ -389,7 +469,7 @@ func TestDirector_HandleRequest(t *testing.T) {
389
469
assert .Equal (t , test .wantReqCtx .Model , returnedReqCtx .Model , "reqCtx.Model mismatch" )
390
470
assert .Equal (t , test .wantReqCtx .ResolvedTargetModel , returnedReqCtx .ResolvedTargetModel ,
391
471
"reqCtx.ResolvedTargetModel mismatch" )
392
- assert .Equal (t , test .wantReqCtx .TargetPod , returnedReqCtx .TargetPod , "reqCtx.TargetPod mismatch" )
472
+ assert .Equal (t , test .wantReqCtx .TargetPods , returnedReqCtx .TargetPods , "reqCtx.TargetPod mismatch" )
393
473
assert .Equal (t , test .wantReqCtx .TargetEndpoint , returnedReqCtx .TargetEndpoint , "reqCtx.TargetEndpoint mismatch" )
394
474
}
395
475
@@ -675,7 +755,7 @@ func TestDirector_HandleResponse(t *testing.T) {
675
755
Headers : map [string ]string {"X-Test-Response-Header" : "TestValue" },
676
756
},
677
757
678
- TargetPod : & backend.Pod {NamespacedName : types.NamespacedName {Namespace : "namespace1" , Name : "test-pod-name" }},
758
+ TargetPods : [] * backend.Pod {{ NamespacedName : types.NamespacedName {Namespace : "namespace1" , Name : "test-pod-name" } }},
679
759
}
680
760
681
761
_ , err := director .HandleResponse (ctx , reqCtx )
0 commit comments