From 4008ea0b4c1835152b587bd2cef7e313e6d2c452 Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Tue, 23 Nov 2021 21:59:46 +0000 Subject: [PATCH] Fix bug in CPUManager map.Keys() and map.Values() implementations Previously these would return lists that were too long because we appended to pre-initialized lists with a specific size. Since the primary place these functions are used is in the mean and standard deviation calculations for the NUMA distribution algorithm, it meant that the results of these calculations were often incorrect. As a result, some of the unit tests we have are actually incorrect (because the results we expect do not actually produce the best balanced distribution of CPUs across all NUMA nodes for the input provided). These tests will be patched up in subsequent commits. Signed-off-by: Kevin Klues --- pkg/kubelet/cm/cpumanager/cpu_assignment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_assignment.go b/pkg/kubelet/cm/cpumanager/cpu_assignment.go index 2f8299c211f..eade5f08ecd 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_assignment.go +++ b/pkg/kubelet/cm/cpumanager/cpu_assignment.go @@ -45,7 +45,7 @@ func (m mapIntInt) Clone() mapIntInt { } func (m mapIntInt) Keys() []int { - keys := make([]int, len(m)) + var keys []int for k := range m { keys = append(keys, k) } @@ -53,7 +53,7 @@ func (m mapIntInt) Keys() []int { } func (m mapIntInt) Values() []int { - values := make([]int, len(m)) + var values []int for _, v := range m { values = append(values, v) }