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