cpuset: Remove *Int64 methods

These are rarely used and can be accommodated with a trivial helper.
This commit is contained in:
Ian K. Coolidge 2022-11-08 05:54:42 +00:00
parent 67a057d4f2
commit a0c989b99a
3 changed files with 15 additions and 33 deletions

View File

@ -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{}
}

View File

@ -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.
//

View File

@ -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")