Skip to content

Commit 93cdd08

Browse files
committed
kubelet/volumemanager: cleanups sort
simplify some usage to sets.Set. use slices.Sort instead of sort.Strings, as of Go 1.22, the former simply calls latter.
1 parent c3689b9 commit 93cdd08

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pkg/kubelet/volumemanager/volume_manager.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"sort"
23+
"slices"
2424
"strconv"
2525
"strings"
2626
"time"
@@ -332,7 +332,7 @@ func (vm *volumeManager) GetExtraSupplementalGroupsForPod(pod *v1.Pod) []int64 {
332332
}
333333

334334
result := make([]int64, 0, supplementalGroups.Len())
335-
for _, group := range sets.List(supplementalGroups) {
335+
for _, group := range supplementalGroups.UnsortedList() {
336336
iGroup, extra := getExtraSupplementalGid(group, pod)
337337
if !extra {
338338
continue
@@ -370,9 +370,7 @@ func (vm *volumeManager) GetVolumesInUse() []v1.UniqueVolumeName {
370370
}
371371
}
372372

373-
sort.Slice(volumesToReportInUse, func(i, j int) bool {
374-
return string(volumesToReportInUse[i]) < string(volumesToReportInUse[j])
375-
})
373+
slices.Sort(volumesToReportInUse)
376374
return volumesToReportInUse
377375
}
378376

@@ -463,12 +461,11 @@ func (vm *volumeManager) WaitForUnmount(ctx context.Context, pod *v1.Pod) error
463461
for _, v := range vm.actualStateOfWorld.GetMountedVolumesForPod(uniquePodName) {
464462
mountedVolumes = append(mountedVolumes, v.OuterVolumeSpecName)
465463
}
466-
sort.Strings(mountedVolumes)
467-
468464
if len(mountedVolumes) == 0 {
469465
return nil
470466
}
471467

468+
slices.Sort(mountedVolumes)
472469
return fmt.Errorf(
473470
"mounted volumes=%v: %w",
474471
mountedVolumes,
@@ -480,7 +477,7 @@ func (vm *volumeManager) WaitForUnmount(ctx context.Context, pod *v1.Pod) error
480477
}
481478

482479
func (vm *volumeManager) getVolumesNotInDSW(uniquePodName types.UniquePodName, expectedVolumes []string) []string {
483-
volumesNotInDSW := sets.New[string](expectedVolumes...)
480+
volumesNotInDSW := sets.New(expectedVolumes...)
484481

485482
for _, volumeToMount := range vm.desiredStateOfWorld.GetVolumesToMount() {
486483
if volumeToMount.PodName == uniquePodName {
@@ -502,7 +499,7 @@ func (vm *volumeManager) getUnattachedVolumes(uniquePodName types.UniquePodName)
502499
unattachedVolumes = append(unattachedVolumes, volumeToMount.OuterVolumeSpecName)
503500
}
504501
}
505-
sort.Strings(unattachedVolumes)
502+
slices.Sort(unattachedVolumes)
506503

507504
return unattachedVolumes
508505
}
@@ -550,7 +547,7 @@ func filterUnmountedVolumes(mountedVolumes sets.Set[string], expectedVolumes []s
550547
unmountedVolumes = append(unmountedVolumes, expectedVolume)
551548
}
552549
}
553-
sort.Strings(unmountedVolumes)
550+
slices.Sort(unmountedVolumes)
554551

555552
return unmountedVolumes
556553
}

0 commit comments

Comments
 (0)