From e6c95e7a5c082b6c7382f7cefc7538c27f710afa Mon Sep 17 00:00:00 2001 From: zhangxiaoyu-zidif Date: Wed, 5 Jul 2017 15:40:51 +0800 Subject: [PATCH] fix-review --- pkg/kubelet/preemption/preemption_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/kubelet/preemption/preemption_test.go b/pkg/kubelet/preemption/preemption_test.go index ea7db60a62..fcd1950c36 100644 --- a/pkg/kubelet/preemption/preemption_test.go +++ b/pkg/kubelet/preemption/preemption_test.go @@ -458,21 +458,21 @@ func admissionRequirementListEqual(list1 admissionRequirementList, list2 admissi return true } -// this 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 +// podListEqual checks if the lists contents contain all of the same elements. func podListEqual(list1 []*v1.Pod, list2 []*v1.Pod) bool { if len(list1) != len(list2) { return false } - for _, a := range list1 { - contains := false - for _, b := range list2 { - if a == b { - contains = true - } - } - if !contains { + + m := map[*v1.Pod]int{} + for _, val := range list1 { + m[val] = m[val] + 1 + } + for _, val := range list2 { + m[val] = m[val] - 1 + } + for _, v := range m { + if v != 0 { return false } }