From 69db36b9583a49d7c32ac8d95998636374dd0a23 Mon Sep 17 00:00:00 2001 From: Artyom Lukianov Date: Mon, 18 Jan 2021 19:59:23 +0200 Subject: [PATCH] Provide additional methods under the CPUSet - ToSliceInt64 returns sorted slice of cores IDs in int64 format - ToSliceNoSortInt64 returns slice of cores IDs in int64 format Signed-off-by: Artyom Lukianov --- pkg/kubelet/cm/cpuset/cpuset.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/cm/cpuset/cpuset.go b/pkg/kubelet/cm/cpuset/cpuset.go index ae2062bd8a8..ad7ea27afa4 100644 --- a/pkg/kubelet/cm/cpuset/cpuset.go +++ b/pkg/kubelet/cm/cpuset/cpuset.go @@ -19,11 +19,12 @@ package cpuset import ( "bytes" "fmt" - "k8s.io/klog/v2" "reflect" "sort" "strconv" "strings" + + "k8s.io/klog/v2" ) // Builder is a mutable builder for CPUSet. Functions that mutate instances @@ -198,6 +199,27 @@ 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 { + var result []int64 + 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 { + var result []int64 + 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. //