Skip to content

Commit b6f3910

Browse files
authored
[kjobctl] refactor to use utilmaps.SortedKeys (#3525)
1 parent 2c8e7da commit b6f3910

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

‎cmd/experimental/kjobctl/pkg/cmd/describe/describe_printer.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/util/duration"
3333
describehelper "k8s.io/kubectl/pkg/describe"
3434
"k8s.io/utils/ptr"
35+
utilmaps "sigs.k8s.io/kueue/pkg/util/maps"
3536
)
3637

3738
// ResourceDescriber generates output for the named resource or an error
@@ -316,16 +317,14 @@ func describeConfigMap(configMap *corev1.ConfigMap) (string, error) {
316317
printLabelsMultiline(w, "Labels", configMap.Labels)
317318

318319
w.Write(IndentLevelZero, "\nData\n====\n")
319-
sortedKeys := sortMapKeys(configMap.Data)
320-
for _, k := range sortedKeys {
320+
for _, k := range utilmaps.SortedKeys(configMap.Data) {
321321
w.Write(IndentLevelZero, "%s:\n----\n", k)
322322
w.Write(IndentLevelZero, "%s\n", configMap.Data[k])
323323
w.Write(IndentLevelZero, "\n")
324324
}
325325

326326
w.Write(IndentLevelZero, "\nBinaryData\n====\n")
327-
sortedKeys = sortMapKeys(configMap.BinaryData)
328-
for _, k := range sortedKeys {
327+
for _, k := range utilmaps.SortedKeys(configMap.BinaryData) {
329328
w.Write(IndentLevelZero, "%s: %s bytes\n", k, strconv.Itoa(len(configMap.BinaryData[k])))
330329
}
331330
w.Write(IndentLevelZero, "\n")

‎cmd/experimental/kjobctl/pkg/cmd/describe/helpers.go‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"slices"
2423
"sort"
2524
"strconv"
2625
"strings"
@@ -99,17 +98,6 @@ func gvkFor(mapper meta.RESTMapper, resource string) (schema.GroupVersionKind, e
9998
return gvk, err
10099
}
101100

102-
func sortMapKeys[T any](m map[string]T) []string {
103-
keys := make([]string, 0, len(m))
104-
for k := range m {
105-
keys = append(keys, k)
106-
}
107-
108-
slices.Sort(keys)
109-
110-
return keys
111-
}
112-
113101
// below functions copied from https://github.com/kubernetes/kubectl/blob/master/pkg/describe/describe.go
114102

115103
func tabbedString(f func(io.Writer) error) (string, error) {

0 commit comments

Comments
 (0)