@@ -417,18 +417,23 @@ func sortDomains(constraintTopologyPairs map[topologyPair][]*v1.Pod, isEvictable
417
417
// followed by the highest priority pods with affinity or nodeSelector
418
418
sort .Slice (list , func (i , j int ) bool {
419
419
// any non-evictable pods should be considered last (ie, first in the list)
420
- if ! isEvictable (list [i ]) || ! isEvictable (list [j ]) {
420
+ evictableI := isEvictable (list [i ])
421
+ evictableJ := isEvictable (list [j ])
422
+
423
+ if ! evictableI || ! evictableJ {
421
424
// false - i is the only non-evictable, so return true to put it first
422
425
// true - j is non-evictable, so return false to put j before i
423
426
// if true and both and non-evictable, order doesn't matter
424
- return ! (isEvictable ( list [ i ]) && ! isEvictable ( list [ j ]) )
427
+ return ! (evictableI && ! evictableJ )
425
428
}
429
+ hasSelectorOrAffinityI := hasSelectorOrAffinity (* list [i ])
430
+ hasSelectorOrAffinityJ := hasSelectorOrAffinity (* list [j ])
426
431
// if both pods have selectors/affinity, compare them by their priority
427
- if hasSelectorOrAffinity ( * list [ i ]) == hasSelectorOrAffinity ( * list [ j ]) {
432
+ if hasSelectorOrAffinityI == hasSelectorOrAffinityJ {
428
433
// Sort by priority in ascending order (lower priority Pods first)
429
434
return ! comparePodsByPriority (list [i ], list [j ])
430
435
}
431
- return hasSelectorOrAffinity ( * list [ i ]) && ! hasSelectorOrAffinity ( * list [ j ])
436
+ return hasSelectorOrAffinityI && ! hasSelectorOrAffinityJ
432
437
})
433
438
sortedTopologies = append (sortedTopologies , topology {pair : pair , pods : list })
434
439
}
0 commit comments