mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-28 14:41:10 +01:00
making isEvictable and hasSelectorOrAffinity invoked only once
Signed-off-by: googs1025 <googs1025@gmail.com>
This commit is contained in:
@@ -417,18 +417,23 @@ func sortDomains(constraintTopologyPairs map[topologyPair][]*v1.Pod, isEvictable
|
|||||||
// followed by the highest priority pods with affinity or nodeSelector
|
// followed by the highest priority pods with affinity or nodeSelector
|
||||||
sort.Slice(list, func(i, j int) bool {
|
sort.Slice(list, func(i, j int) bool {
|
||||||
// any non-evictable pods should be considered last (ie, first in the list)
|
// any non-evictable pods should be considered last (ie, first in the list)
|
||||||
if !isEvictable(list[i]) || !isEvictable(list[j]) {
|
evictableI := isEvictable(list[i])
|
||||||
|
evictableJ := isEvictable(list[j])
|
||||||
|
|
||||||
|
if !evictableI || !evictableJ {
|
||||||
// false - i is the only non-evictable, so return true to put it first
|
// false - i is the only non-evictable, so return true to put it first
|
||||||
// true - j is non-evictable, so return false to put j before i
|
// true - j is non-evictable, so return false to put j before i
|
||||||
// if true and both and non-evictable, order doesn't matter
|
// if true and both and non-evictable, order doesn't matter
|
||||||
return !(isEvictable(list[i]) && !isEvictable(list[j]))
|
return !(evictableI && !evictableJ)
|
||||||
}
|
}
|
||||||
|
hasSelectorOrAffinityI := hasSelectorOrAffinity(*list[i])
|
||||||
|
hasSelectorOrAffinityJ := hasSelectorOrAffinity(*list[j])
|
||||||
// if both pods have selectors/affinity, compare them by their priority
|
// if both pods have selectors/affinity, compare them by their priority
|
||||||
if hasSelectorOrAffinity(*list[i]) == hasSelectorOrAffinity(*list[j]) {
|
if hasSelectorOrAffinityI == hasSelectorOrAffinityJ {
|
||||||
// Sort by priority in ascending order (lower priority Pods first)
|
// Sort by priority in ascending order (lower priority Pods first)
|
||||||
return !comparePodsByPriority(list[i], list[j])
|
return !comparePodsByPriority(list[i], list[j])
|
||||||
}
|
}
|
||||||
return hasSelectorOrAffinity(*list[i]) && !hasSelectorOrAffinity(*list[j])
|
return hasSelectorOrAffinityI && !hasSelectorOrAffinityJ
|
||||||
})
|
})
|
||||||
sortedTopologies = append(sortedTopologies, topology{pair: pair, pods: list})
|
sortedTopologies = append(sortedTopologies, topology{pair: pair, pods: list})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user