mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #48473 from zhangxiaoyu-zidif/refactor-preemption
Automatic merge from submit-queue (batch tested with PRs 48473, 48341) Refactor podListEqual() **What this PR does / why we need it**: To solve the problem: this is not correct if there are duplicate pods in the list. for example: podListEqual([a, a, b], [a, b, b]) will return true **Special notes for your reviewer**: the original method is O(N^2), while current method is 3* O(N). I think it is much better. **Release note**: ```release-note NONE ```
This commit is contained in:
commit
62d3e8c25f
@ -458,21 +458,21 @@ func admissionRequirementListEqual(list1 admissionRequirementList, list2 admissi
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// this checks if the lists contents contain all of the same elements.
|
// podListEqual checks if the lists contents contain all of the same elements.
|
||||||
// this is not correct if there are duplicate pods in the list.
|
|
||||||
// for example: podListEqual([a, a, b], [a, b, b]) will return true
|
|
||||||
func podListEqual(list1 []*v1.Pod, list2 []*v1.Pod) bool {
|
func podListEqual(list1 []*v1.Pod, list2 []*v1.Pod) bool {
|
||||||
if len(list1) != len(list2) {
|
if len(list1) != len(list2) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, a := range list1 {
|
|
||||||
contains := false
|
m := map[*v1.Pod]int{}
|
||||||
for _, b := range list2 {
|
for _, val := range list1 {
|
||||||
if a == b {
|
m[val] = m[val] + 1
|
||||||
contains = true
|
}
|
||||||
}
|
for _, val := range list2 {
|
||||||
}
|
m[val] = m[val] - 1
|
||||||
if !contains {
|
}
|
||||||
|
for _, v := range m {
|
||||||
|
if v != 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user