1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

Merge pull request #336 from lixiang233/avoid_duplicated_append_RemoveDuplicatePods

avoid appending list multiple times in RemoveDuplicates
This commit is contained in:
Kubernetes Prow Robot
2020-07-09 01:32:02 -07:00
committed by GitHub

View File

@@ -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 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 { if existing, ok := duplicateKeysMap[podContainerKeys[0]]; ok {
matched := false
for _, keys := range existing { for _, keys := range existing {
if reflect.DeepEqual(keys, podContainerKeys) { if reflect.DeepEqual(keys, podContainerKeys) {
matched = true
duplicatePods = append(duplicatePods, pod) duplicatePods = append(duplicatePods, pod)
break break
} }
}
if !matched {
// Found no matches, add this list of keys to the list of lists that have the same first key // 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) duplicateKeysMap[podContainerKeys[0]] = append(duplicateKeysMap[podContainerKeys[0]], podContainerKeys)
} }