mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
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.
This commit is contained in:
parent
c3689b9f8b
commit
93cdd08dcd
@ -20,7 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -332,7 +332,7 @@ func (vm *volumeManager) GetExtraSupplementalGroupsForPod(pod *v1.Pod) []int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result := make([]int64, 0, supplementalGroups.Len())
|
result := make([]int64, 0, supplementalGroups.Len())
|
||||||
for _, group := range sets.List(supplementalGroups) {
|
for _, group := range supplementalGroups.UnsortedList() {
|
||||||
iGroup, extra := getExtraSupplementalGid(group, pod)
|
iGroup, extra := getExtraSupplementalGid(group, pod)
|
||||||
if !extra {
|
if !extra {
|
||||||
continue
|
continue
|
||||||
@ -370,9 +370,7 @@ func (vm *volumeManager) GetVolumesInUse() []v1.UniqueVolumeName {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(volumesToReportInUse, func(i, j int) bool {
|
slices.Sort(volumesToReportInUse)
|
||||||
return string(volumesToReportInUse[i]) < string(volumesToReportInUse[j])
|
|
||||||
})
|
|
||||||
return volumesToReportInUse
|
return volumesToReportInUse
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,12 +461,11 @@ func (vm *volumeManager) WaitForUnmount(ctx context.Context, pod *v1.Pod) error
|
|||||||
for _, v := range vm.actualStateOfWorld.GetMountedVolumesForPod(uniquePodName) {
|
for _, v := range vm.actualStateOfWorld.GetMountedVolumesForPod(uniquePodName) {
|
||||||
mountedVolumes = append(mountedVolumes, v.OuterVolumeSpecName)
|
mountedVolumes = append(mountedVolumes, v.OuterVolumeSpecName)
|
||||||
}
|
}
|
||||||
sort.Strings(mountedVolumes)
|
|
||||||
|
|
||||||
if len(mountedVolumes) == 0 {
|
if len(mountedVolumes) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slices.Sort(mountedVolumes)
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"mounted volumes=%v: %w",
|
"mounted volumes=%v: %w",
|
||||||
mountedVolumes,
|
mountedVolumes,
|
||||||
@ -480,7 +477,7 @@ func (vm *volumeManager) WaitForUnmount(ctx context.Context, pod *v1.Pod) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vm *volumeManager) getVolumesNotInDSW(uniquePodName types.UniquePodName, expectedVolumes []string) []string {
|
func (vm *volumeManager) getVolumesNotInDSW(uniquePodName types.UniquePodName, expectedVolumes []string) []string {
|
||||||
volumesNotInDSW := sets.New[string](expectedVolumes...)
|
volumesNotInDSW := sets.New(expectedVolumes...)
|
||||||
|
|
||||||
for _, volumeToMount := range vm.desiredStateOfWorld.GetVolumesToMount() {
|
for _, volumeToMount := range vm.desiredStateOfWorld.GetVolumesToMount() {
|
||||||
if volumeToMount.PodName == uniquePodName {
|
if volumeToMount.PodName == uniquePodName {
|
||||||
@ -502,7 +499,7 @@ func (vm *volumeManager) getUnattachedVolumes(uniquePodName types.UniquePodName)
|
|||||||
unattachedVolumes = append(unattachedVolumes, volumeToMount.OuterVolumeSpecName)
|
unattachedVolumes = append(unattachedVolumes, volumeToMount.OuterVolumeSpecName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Strings(unattachedVolumes)
|
slices.Sort(unattachedVolumes)
|
||||||
|
|
||||||
return unattachedVolumes
|
return unattachedVolumes
|
||||||
}
|
}
|
||||||
@ -550,7 +547,7 @@ func filterUnmountedVolumes(mountedVolumes sets.Set[string], expectedVolumes []s
|
|||||||
unmountedVolumes = append(unmountedVolumes, expectedVolume)
|
unmountedVolumes = append(unmountedVolumes, expectedVolume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Strings(unmountedVolumes)
|
slices.Sort(unmountedVolumes)
|
||||||
|
|
||||||
return unmountedVolumes
|
return unmountedVolumes
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user