diff --git a/pkg/kubelet/cm/container_manager_linux.go b/pkg/kubelet/cm/container_manager_linux.go index 332e99e72ee..79e50fa4975 100644 --- a/pkg/kubelet/cm/container_manager_linux.go +++ b/pkg/kubelet/cm/container_manager_linux.go @@ -972,16 +972,24 @@ func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.Conta return containerDevicesFromResourceDeviceInstances(cm.deviceManager.GetAllocatableDevices()) } +func int64Slice(in []int) []int64 { + out := make([]int64, len(in)) + for i := range in { + out[i] = int64(in[i]) + } + return out +} + func (cm *containerManagerImpl) GetCPUs(podUID, containerName string) []int64 { if cm.cpuManager != nil { - return cm.cpuManager.GetExclusiveCPUs(podUID, containerName).ToSliceNoSortInt64() + return int64Slice(cm.cpuManager.GetExclusiveCPUs(podUID, containerName).ToSliceNoSort()) } return []int64{} } func (cm *containerManagerImpl) GetAllocatableCPUs() []int64 { if cm.cpuManager != nil { - return cm.cpuManager.GetAllocatableCPUs().ToSliceNoSortInt64() + return int64Slice(cm.cpuManager.GetAllocatableCPUs().ToSliceNoSort()) } return []int64{} } diff --git a/pkg/kubelet/cm/cpuset/cpuset.go b/pkg/kubelet/cm/cpuset/cpuset.go index f120bbe34b8..4abcddb6ac5 100644 --- a/pkg/kubelet/cm/cpuset/cpuset.go +++ b/pkg/kubelet/cm/cpuset/cpuset.go @@ -73,15 +73,6 @@ func NewCPUSet(cpus ...int) CPUSet { return b.Result() } -// NewCPUSetInt64 returns a new CPUSet containing the supplied elements, as slice of int64. -func NewCPUSetInt64(cpus ...int64) CPUSet { - b := NewBuilder() - for _, c := range cpus { - b.Add(int(c)) - } - return b.Result() -} - // Size returns the number of elements in this set. func (s CPUSet) Size() int { return len(s.elems) @@ -192,27 +183,6 @@ func (s CPUSet) ToSliceNoSort() []int { return result } -// ToSliceInt64 returns an ordered slice of int64 that contains all elements from -// this set -func (s CPUSet) ToSliceInt64() []int64 { - result := make([]int64, 0, len(s.elems)) - for cpu := range s.elems { - result = append(result, int64(cpu)) - } - sort.Slice(result, func(i, j int) bool { return result[i] < result[j] }) - return result -} - -// ToSliceNoSortInt64 returns a slice of int64 that contains all elements from -// this set. -func (s CPUSet) ToSliceNoSortInt64() []int64 { - result := make([]int64, 0, len(s.elems)) - for cpu := range s.elems { - result = append(result, int64(cpu)) - } - return result -} - // String returns a new string representation of the elements in this CPU set // in canonical linux CPU list format. // diff --git a/test/e2e_node/podresources_test.go b/test/e2e_node/podresources_test.go index a2686b41dee..996df0cd7c1 100644 --- a/test/e2e_node/podresources_test.go +++ b/test/e2e_node/podresources_test.go @@ -522,7 +522,11 @@ func podresourcesGetAllocatableResourcesTests(ctx context.Context, cli kubeletpo resp, err := cli.GetAllocatableResources(ctx, &kubeletpodresourcesv1.AllocatableResourcesRequest{}) framework.ExpectNoErrorWithOffset(1, err) devs := resp.GetDevices() - allocatableCPUs := cpuset.NewCPUSetInt64(resp.GetCpuIds()...) + b := cpuset.NewBuilder() + for _, cpuid := range resp.GetCpuIds() { + b.Add(int(cpuid)) + } + allocatableCPUs := b.Result() if onlineCPUs.Size() == 0 { ginkgo.By("expecting no CPUs reported")