From cd8b5a03540666e4727755f827cf611ca059117c Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 7 Jul 2020 14:42:53 +0800 Subject: [PATCH] avoid appending list multiple times in RemoveDuplicates --- pkg/descheduler/strategies/duplicates.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/descheduler/strategies/duplicates.go b/pkg/descheduler/strategies/duplicates.go index cf5904f84..9a276f910 100644 --- a/pkg/descheduler/strategies/duplicates.go +++ b/pkg/descheduler/strategies/duplicates.go @@ -86,11 +86,15 @@ func RemoveDuplicatePods( // If there have been any other pods with the same first "key", look through all the lists to see if any match if existing, ok := duplicateKeysMap[podContainerKeys[0]]; ok { + matched := false for _, keys := range existing { if reflect.DeepEqual(keys, podContainerKeys) { + matched = true duplicatePods = append(duplicatePods, pod) break } + } + if !matched { // Found no matches, add this list of keys to the list of lists that have the same first key duplicateKeysMap[podContainerKeys[0]] = append(duplicateKeysMap[podContainerKeys[0]], podContainerKeys) }