@@ -274,16 +274,16 @@ func TestSchedulePlugins(t *testing.T) {
274274 tp1 : 1 ,
275275 tp2 : 1 ,
276276 },
277- postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
278277 picker : pickerPlugin ,
278+ postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
279279 },
280280 input : []* backendmetrics.FakePodMetrics {
281281 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}},
282282 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}},
283283 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod3" }}},
284284 },
285285 wantTargetPod : k8stypes.NamespacedName {Name : "pod1" },
286- targetPodScore : 0.55 ,
286+ targetPodScore : 1.1 ,
287287 numPodsToScore : 2 ,
288288 err : false ,
289289 },
@@ -296,16 +296,16 @@ func TestSchedulePlugins(t *testing.T) {
296296 tp1 : 60 ,
297297 tp2 : 40 ,
298298 },
299- postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
300299 picker : pickerPlugin ,
300+ postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
301301 },
302302 input : []* backendmetrics.FakePodMetrics {
303303 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}},
304304 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}},
305305 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod3" }}},
306306 },
307307 wantTargetPod : k8stypes.NamespacedName {Name : "pod1" },
308- targetPodScore : 0.5 ,
308+ targetPodScore : 50 ,
309309 numPodsToScore : 2 ,
310310 err : false ,
311311 },
@@ -318,8 +318,8 @@ func TestSchedulePlugins(t *testing.T) {
318318 tp1 : 1 ,
319319 tp2 : 1 ,
320320 },
321- postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
322321 picker : pickerPlugin ,
322+ postSchedulePlugins : []plugins.PostSchedule {tp1 , tp2 },
323323 },
324324 input : []* backendmetrics.FakePodMetrics {
325325 {Pod : & backendmetrics.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}},
@@ -337,16 +337,16 @@ func TestSchedulePlugins(t *testing.T) {
337337 for _ , plugin := range test .config .preSchedulePlugins {
338338 plugin .(* TestPlugin ).reset ()
339339 }
340- for _ , plugin := range test .config .postSchedulePlugins {
341- plugin .(* TestPlugin ).reset ()
342- }
343340 for _ , plugin := range test .config .filters {
344341 plugin .(* TestPlugin ).reset ()
345342 }
346343 for plugin := range test .config .scorers {
347344 plugin .(* TestPlugin ).reset ()
348345 }
349346 test .config .picker .(* TestPlugin ).reset ()
347+ for _ , plugin := range test .config .postSchedulePlugins {
348+ plugin .(* TestPlugin ).reset ()
349+ }
350350
351351 // Initialize the scheduler
352352 scheduler := NewSchedulerWithConfig (& fakeDataStore {pods : test .input }, & test .config )
@@ -397,13 +397,6 @@ func TestSchedulePlugins(t *testing.T) {
397397 }
398398 }
399399
400- for _ , plugin := range test .config .postSchedulePlugins {
401- tp , _ := plugin .(* TestPlugin )
402- if tp .PostScheduleCallCount != 1 {
403- t .Errorf ("Plugin %s PostSchedule() called %d times, expected 1" , plugin .Name (), tp .PostScheduleCallCount )
404- }
405- }
406-
407400 tp , _ := test .config .picker .(* TestPlugin )
408401 if tp .NumOfPickerCandidates != test .numPodsToScore {
409402 t .Errorf ("Picker plugin %s Pick() called with %d candidates, expected %d" , tp .Name (), tp .NumOfPickerCandidates , tp .NumOfScoredPods )
@@ -414,6 +407,13 @@ func TestSchedulePlugins(t *testing.T) {
414407 if tp .WinnderPodScore != test .targetPodScore {
415408 t .Errorf ("winnder pod score %v, expected %v" , tp .WinnderPodScore , test .targetPodScore )
416409 }
410+
411+ for _ , plugin := range test .config .postSchedulePlugins {
412+ tp , _ := plugin .(* TestPlugin )
413+ if tp .PostScheduleCallCount != 1 {
414+ t .Errorf ("Plugin %s PostSchedule() called %d times, expected 1" , plugin .Name (), tp .PostScheduleCallCount )
415+ }
416+ }
417417 })
418418 }
419419}
@@ -468,18 +468,18 @@ func (tp *TestPlugin) Score(ctx *types.SchedulingContext, pods []types.Pod) map[
468468 return scoredPods
469469}
470470
471- func (tp * TestPlugin ) PostSchedule (ctx * types.SchedulingContext , res * types.Result ) {
472- tp .PostScheduleCallCount ++
473- }
474-
475- func (tp * TestPlugin ) Pick (ctx * types.SchedulingContext , scoredPods map [types.Pod ]float64 ) * types.Result {
471+ func (tp * TestPlugin ) Pick (ctx * types.SchedulingContext , scoredPods []* types.ScoredPod ) * types.Result {
476472 tp .PickCallCount ++
477473 tp .NumOfPickerCandidates = len (scoredPods )
478474 pod := findPods (ctx , tp .PickRes )[0 ]
479- tp .WinnderPodScore = scoredPods [ pod ]
475+ tp .WinnderPodScore = getPodScore ( scoredPods , pod )
480476 return & types.Result {TargetPod : pod }
481477}
482478
479+ func (tp * TestPlugin ) PostSchedule (ctx * types.SchedulingContext , res * types.Result ) {
480+ tp .PostScheduleCallCount ++
481+ }
482+
483483func (tp * TestPlugin ) reset () {
484484 tp .PreScheduleCallCount = 0
485485 tp .FilterCallCount = 0
@@ -501,3 +501,14 @@ func findPods(ctx *types.SchedulingContext, names ...k8stypes.NamespacedName) []
501501 }
502502 return res
503503}
504+
505+ func getPodScore (scoredPods []* types.ScoredPod , selectedPod types.Pod ) float64 {
506+ finalScore := 0.0
507+ for _ , scoredPod := range scoredPods {
508+ if scoredPod .Pod .GetPod ().NamespacedName .String () == selectedPod .GetPod ().NamespacedName .String () {
509+ finalScore = scoredPod .Score
510+ break
511+ }
512+ }
513+ return finalScore
514+ }
0 commit comments