mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #82123 from xiaoanyunfei/cleanup/take-effect-stateofworld-hashmap
replace iteration with hashmap in *state_of_world
This commit is contained in:
commit
4b002b3baa
@ -569,13 +569,10 @@ func (asw *actualStateOfWorld) GetAttachedVolumesForNode(
|
||||
attachedVolumes := make(
|
||||
[]AttachedVolume, 0 /* len */, len(asw.attachedVolumes) /* cap */)
|
||||
for _, volumeObj := range asw.attachedVolumes {
|
||||
for actualNodeName, nodeObj := range volumeObj.nodesAttachedTo {
|
||||
if actualNodeName == nodeName {
|
||||
attachedVolumes = append(
|
||||
attachedVolumes,
|
||||
getAttachedVolume(&volumeObj, &nodeObj))
|
||||
break
|
||||
}
|
||||
if nodeObj, nodeExists := volumeObj.nodesAttachedTo[nodeName]; nodeExists {
|
||||
attachedVolumes = append(
|
||||
attachedVolumes,
|
||||
getAttachedVolume(&volumeObj, &nodeObj))
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,9 +607,9 @@ func (asw *actualStateOfWorld) GetNodesForAttachedVolume(volumeName v1.UniqueVol
|
||||
}
|
||||
|
||||
nodes := []types.NodeName{}
|
||||
for k, nodesAttached := range volumeObj.nodesAttachedTo {
|
||||
for nodeName, nodesAttached := range volumeObj.nodesAttachedTo {
|
||||
if nodesAttached.attachedConfirmed {
|
||||
nodes = append(nodes, k)
|
||||
nodes = append(nodes, nodeName)
|
||||
}
|
||||
}
|
||||
return nodes
|
||||
@ -627,14 +624,14 @@ func (asw *actualStateOfWorld) GetVolumesToReportAttached() map[types.NodeName][
|
||||
if nodeToUpdateObj.statusUpdateNeeded {
|
||||
attachedVolumes := make(
|
||||
[]v1.AttachedVolume,
|
||||
0,
|
||||
len(nodeToUpdateObj.volumesToReportAsAttached) /* len */)
|
||||
i := 0
|
||||
for _, volume := range nodeToUpdateObj.volumesToReportAsAttached {
|
||||
attachedVolumes[i] = v1.AttachedVolume{
|
||||
Name: volume,
|
||||
DevicePath: asw.attachedVolumes[volume].devicePath,
|
||||
}
|
||||
i++
|
||||
attachedVolumes = append(attachedVolumes,
|
||||
v1.AttachedVolume{
|
||||
Name: volume,
|
||||
DevicePath: asw.attachedVolumes[volume].devicePath,
|
||||
})
|
||||
}
|
||||
volumesToReportAttached[nodeToUpdateObj.nodeName] = attachedVolumes
|
||||
}
|
||||
|
@ -492,11 +492,7 @@ func (asw *actualStateOfWorld) MarkRemountRequired(
|
||||
asw.Lock()
|
||||
defer asw.Unlock()
|
||||
for volumeName, volumeObj := range asw.attachedVolumes {
|
||||
for mountedPodName, podObj := range volumeObj.mountedPods {
|
||||
if mountedPodName != podName {
|
||||
continue
|
||||
}
|
||||
|
||||
if podObj, podExists := volumeObj.mountedPods[podName]; podExists {
|
||||
volumePlugin, err :=
|
||||
asw.volumePluginMgr.FindPluginBySpec(podObj.volumeSpec)
|
||||
if err != nil || volumePlugin == nil {
|
||||
@ -523,14 +519,14 @@ func (asw *actualStateOfWorld) MarkFSResizeRequired(
|
||||
podName volumetypes.UniquePodName) {
|
||||
asw.Lock()
|
||||
defer asw.Unlock()
|
||||
volumeObj, exist := asw.attachedVolumes[volumeName]
|
||||
if !exist {
|
||||
volumeObj, volumeExists := asw.attachedVolumes[volumeName]
|
||||
if !volumeExists {
|
||||
klog.Warningf("MarkFSResizeRequired for volume %s failed as volume not exist", volumeName)
|
||||
return
|
||||
}
|
||||
|
||||
podObj, exist := volumeObj.mountedPods[podName]
|
||||
if !exist {
|
||||
podObj, podExists := volumeObj.mountedPods[podName]
|
||||
if !podExists {
|
||||
klog.Warningf("MarkFSResizeRequired for volume %s failed "+
|
||||
"as pod(%s) not exist", volumeName, podName)
|
||||
return
|
||||
@ -648,8 +644,8 @@ func (asw *actualStateOfWorld) VolumeExistsWithSpecName(podName volumetypes.Uniq
|
||||
asw.RLock()
|
||||
defer asw.RUnlock()
|
||||
for _, volumeObj := range asw.attachedVolumes {
|
||||
for name, podObj := range volumeObj.mountedPods {
|
||||
if podName == name && podObj.volumeSpec.Name() == volumeSpecName {
|
||||
if podObj, podExists := volumeObj.mountedPods[podName]; podExists {
|
||||
if podObj.volumeSpec.Name() == volumeSpecName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -687,12 +683,10 @@ func (asw *actualStateOfWorld) GetMountedVolumesForPod(
|
||||
defer asw.RUnlock()
|
||||
mountedVolume := make([]MountedVolume, 0 /* len */, len(asw.attachedVolumes) /* cap */)
|
||||
for _, volumeObj := range asw.attachedVolumes {
|
||||
for mountedPodName, podObj := range volumeObj.mountedPods {
|
||||
if mountedPodName == podName {
|
||||
mountedVolume = append(
|
||||
mountedVolume,
|
||||
getMountedVolume(&podObj, &volumeObj))
|
||||
}
|
||||
if podObj, podExists := volumeObj.mountedPods[podName]; podExists {
|
||||
mountedVolume = append(
|
||||
mountedVolume,
|
||||
getMountedVolume(&podObj, &volumeObj))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,8 +362,8 @@ func (dsw *desiredStateOfWorld) VolumeExistsWithSpecName(podName types.UniquePod
|
||||
dsw.RLock()
|
||||
defer dsw.RUnlock()
|
||||
for _, volumeObj := range dsw.volumesToMount {
|
||||
for name, podObj := range volumeObj.podsToMount {
|
||||
if podName == name && podObj.volumeSpec.Name() == volumeSpecName {
|
||||
if podObj, podExists := volumeObj.podsToMount[podName]; podExists {
|
||||
if podObj.volumeSpec.Name() == volumeSpecName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -378,9 +378,7 @@ func (dsw *desiredStateOfWorld) GetPods() map[types.UniquePodName]bool {
|
||||
podList := make(map[types.UniquePodName]bool)
|
||||
for _, volumeObj := range dsw.volumesToMount {
|
||||
for podName := range volumeObj.podsToMount {
|
||||
if !podList[podName] {
|
||||
podList[podName] = true
|
||||
}
|
||||
podList[podName] = true
|
||||
}
|
||||
}
|
||||
return podList
|
||||
|
Loading…
Reference in New Issue
Block a user