mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #126575 from Lucaber/volume-attach-memory-allocations
Reduce memory usage/allocations during wait for volume attachment
This commit is contained in:
commit
83a1310228
@ -120,6 +120,9 @@ type ActualStateOfWorld interface {
|
|||||||
// and false is returned.
|
// and false is returned.
|
||||||
PodRemovedFromVolume(podName volumetypes.UniquePodName, volumeName v1.UniqueVolumeName) bool
|
PodRemovedFromVolume(podName volumetypes.UniquePodName, volumeName v1.UniqueVolumeName) bool
|
||||||
|
|
||||||
|
// PodHasMountedVolumes returns true if any volume is mounted on the given pod
|
||||||
|
PodHasMountedVolumes(podName volumetypes.UniquePodName) bool
|
||||||
|
|
||||||
// VolumeExistsWithSpecName returns true if the given volume specified with the
|
// VolumeExistsWithSpecName returns true if the given volume specified with the
|
||||||
// volume spec name (a.k.a., InnerVolumeSpecName) exists in the list of
|
// volume spec name (a.k.a., InnerVolumeSpecName) exists in the list of
|
||||||
// volumes that should be attached to this node.
|
// volumes that should be attached to this node.
|
||||||
@ -146,6 +149,10 @@ type ActualStateOfWorld interface {
|
|||||||
// current actual state of the world.
|
// current actual state of the world.
|
||||||
GetMountedVolumesForPod(podName volumetypes.UniquePodName) []MountedVolume
|
GetMountedVolumesForPod(podName volumetypes.UniquePodName) []MountedVolume
|
||||||
|
|
||||||
|
// GetMountedVolumeForPodByOuterVolumeSpecName returns the volume and true if
|
||||||
|
// the given outerVolumeSpecName is mounted on the given pod.
|
||||||
|
GetMountedVolumeForPodByOuterVolumeSpecName(podName volumetypes.UniquePodName, outerVolumeSpecName string) (MountedVolume, bool)
|
||||||
|
|
||||||
// GetPossiblyMountedVolumesForPod generates and returns a list of volumes for
|
// GetPossiblyMountedVolumesForPod generates and returns a list of volumes for
|
||||||
// the specified pod that either are attached and mounted or are "uncertain",
|
// the specified pod that either are attached and mounted or are "uncertain",
|
||||||
// i.e. a volume plugin may be mounting the volume right now.
|
// i.e. a volume plugin may be mounting the volume right now.
|
||||||
@ -948,6 +955,20 @@ func (asw *actualStateOfWorld) PodExistsInVolume(podName volumetypes.UniquePodNa
|
|||||||
return podExists, volumeObj.devicePath, nil
|
return podExists, volumeObj.devicePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (asw *actualStateOfWorld) PodHasMountedVolumes(podName volumetypes.UniquePodName) bool {
|
||||||
|
asw.RLock()
|
||||||
|
defer asw.RUnlock()
|
||||||
|
for _, volumeObj := range asw.attachedVolumes {
|
||||||
|
if podObj, hasPod := volumeObj.mountedPods[podName]; hasPod {
|
||||||
|
if podObj.volumeMountStateForPod == operationexecutor.VolumeMounted {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (asw *actualStateOfWorld) volumeNeedsExpansion(volumeObj attachedVolume, desiredVolumeSize resource.Quantity) (resource.Quantity, bool) {
|
func (asw *actualStateOfWorld) volumeNeedsExpansion(volumeObj attachedVolume, desiredVolumeSize resource.Quantity) (resource.Quantity, bool) {
|
||||||
currentSize := resource.Quantity{}
|
currentSize := resource.Quantity{}
|
||||||
if volumeObj.persistentVolumeSize != nil {
|
if volumeObj.persistentVolumeSize != nil {
|
||||||
@ -1063,7 +1084,7 @@ func (asw *actualStateOfWorld) GetMountedVolumesForPod(
|
|||||||
podName volumetypes.UniquePodName) []MountedVolume {
|
podName volumetypes.UniquePodName) []MountedVolume {
|
||||||
asw.RLock()
|
asw.RLock()
|
||||||
defer asw.RUnlock()
|
defer asw.RUnlock()
|
||||||
mountedVolume := make([]MountedVolume, 0 /* len */, len(asw.attachedVolumes) /* cap */)
|
mountedVolume := make([]MountedVolume, 0 /* len */)
|
||||||
for _, volumeObj := range asw.attachedVolumes {
|
for _, volumeObj := range asw.attachedVolumes {
|
||||||
for mountedPodName, podObj := range volumeObj.mountedPods {
|
for mountedPodName, podObj := range volumeObj.mountedPods {
|
||||||
if mountedPodName == podName && podObj.volumeMountStateForPod == operationexecutor.VolumeMounted {
|
if mountedPodName == podName && podObj.volumeMountStateForPod == operationexecutor.VolumeMounted {
|
||||||
@ -1077,6 +1098,21 @@ func (asw *actualStateOfWorld) GetMountedVolumesForPod(
|
|||||||
return mountedVolume
|
return mountedVolume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (asw *actualStateOfWorld) GetMountedVolumeForPodByOuterVolumeSpecName(
|
||||||
|
podName volumetypes.UniquePodName, outerVolumeSpecName string) (MountedVolume, bool) {
|
||||||
|
asw.RLock()
|
||||||
|
defer asw.RUnlock()
|
||||||
|
for _, volumeObj := range asw.attachedVolumes {
|
||||||
|
if podObj, hasPod := volumeObj.mountedPods[podName]; hasPod {
|
||||||
|
if podObj.volumeMountStateForPod == operationexecutor.VolumeMounted && podObj.outerVolumeSpecName == outerVolumeSpecName {
|
||||||
|
return getMountedVolume(&podObj, &volumeObj), true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MountedVolume{}, false
|
||||||
|
}
|
||||||
|
|
||||||
func (asw *actualStateOfWorld) GetPossiblyMountedVolumesForPod(
|
func (asw *actualStateOfWorld) GetPossiblyMountedVolumesForPod(
|
||||||
podName volumetypes.UniquePodName) []MountedVolume {
|
podName volumetypes.UniquePodName) []MountedVolume {
|
||||||
asw.RLock()
|
asw.RLock()
|
||||||
|
@ -540,7 +540,13 @@ func (vm *volumeManager) verifyVolumesMountedFunc(podName types.UniquePodName, e
|
|||||||
if errs := vm.desiredStateOfWorld.PopPodErrors(podName); len(errs) > 0 {
|
if errs := vm.desiredStateOfWorld.PopPodErrors(podName); len(errs) > 0 {
|
||||||
return true, errors.New(strings.Join(errs, "; "))
|
return true, errors.New(strings.Join(errs, "; "))
|
||||||
}
|
}
|
||||||
return len(vm.getUnmountedVolumes(podName, expectedVolumes)) == 0, nil
|
for _, expectedVolume := range expectedVolumes {
|
||||||
|
_, found := vm.actualStateOfWorld.GetMountedVolumeForPodByOuterVolumeSpecName(podName, expectedVolume)
|
||||||
|
if !found {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,7 +557,7 @@ func (vm *volumeManager) verifyVolumesUnmountedFunc(podName types.UniquePodName)
|
|||||||
if errs := vm.desiredStateOfWorld.PopPodErrors(podName); len(errs) > 0 {
|
if errs := vm.desiredStateOfWorld.PopPodErrors(podName); len(errs) > 0 {
|
||||||
return true, errors.New(strings.Join(errs, "; "))
|
return true, errors.New(strings.Join(errs, "; "))
|
||||||
}
|
}
|
||||||
return len(vm.actualStateOfWorld.GetMountedVolumesForPod(podName)) == 0, nil
|
return !vm.actualStateOfWorld.PodHasMountedVolumes(podName), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user