Skip to content

Commit 7f7d720

Browse files
committed
kubelet/volumemanager: simplify GetVolumesInUse
remove the map[v1.UniqueVolumeName]bool allocation and also accelerate this func.
1 parent 93cdd08 commit 7f7d720

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

pkg/kubelet/volumemanager/volume_manager.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,27 +351,21 @@ func (vm *volumeManager) GetVolumesInUse() []v1.UniqueVolumeName {
351351
desiredVolumes := vm.desiredStateOfWorld.GetVolumesToMount()
352352
allAttachedVolumes := vm.actualStateOfWorld.GetAttachedVolumes()
353353
volumesToReportInUse := make([]v1.UniqueVolumeName, 0, len(desiredVolumes)+len(allAttachedVolumes))
354-
desiredVolumesMap := make(map[v1.UniqueVolumeName]bool, len(desiredVolumes)+len(allAttachedVolumes))
355354

356355
for _, volume := range desiredVolumes {
357356
if volume.PluginIsAttachable {
358-
if _, exists := desiredVolumesMap[volume.VolumeName]; !exists {
359-
desiredVolumesMap[volume.VolumeName] = true
360-
volumesToReportInUse = append(volumesToReportInUse, volume.VolumeName)
361-
}
357+
volumesToReportInUse = append(volumesToReportInUse, volume.VolumeName)
362358
}
363359
}
364360

365361
for _, volume := range allAttachedVolumes {
366362
if volume.PluginIsAttachable {
367-
if _, exists := desiredVolumesMap[volume.VolumeName]; !exists {
368-
volumesToReportInUse = append(volumesToReportInUse, volume.VolumeName)
369-
}
363+
volumesToReportInUse = append(volumesToReportInUse, volume.VolumeName)
370364
}
371365
}
372366

373367
slices.Sort(volumesToReportInUse)
374-
return volumesToReportInUse
368+
return slices.Compact(volumesToReportInUse)
375369
}
376370

377371
func (vm *volumeManager) ReconcilerStatesHasBeenSynced() bool {

0 commit comments

Comments
 (0)