mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Add PodRemovedFromVolume
To know when a volume has been fully unmounted (incl. uncertain mounts).
This commit is contained in:
parent
ca934b8f5c
commit
2fcb5e9cf7
@ -71,7 +71,7 @@ func (kl *Kubelet) ListBlockVolumesForPod(podUID types.UID) (map[string]volume.B
|
||||
}
|
||||
|
||||
// podVolumesExist checks with the volume manager and returns true any of the
|
||||
// pods for the specified volume are mounted.
|
||||
// pods for the specified volume are mounted or are uncertain.
|
||||
func (kl *Kubelet) podVolumesExist(podUID types.UID) bool {
|
||||
if mountedVolumes :=
|
||||
kl.volumeManager.GetPossiblyMountedVolumesForPod(
|
||||
|
@ -110,6 +110,14 @@ type ActualStateOfWorld interface {
|
||||
// volumes that do not need to update contents should not fail.
|
||||
PodExistsInVolume(podName volumetypes.UniquePodName, volumeName v1.UniqueVolumeName) (bool, string, error)
|
||||
|
||||
// PodRemovedFromVolume returns true if the given pod does not exist in the list of
|
||||
// mountedPods for the given volume in the cache, indicating that the pod has
|
||||
// fully unmounted it or it was never mounted the volume.
|
||||
// If the volume is fully mounted or is in uncertain mount state for the pod, it is
|
||||
// considered that the pod still exists in volume manager's actual state of the world
|
||||
// and false is returned.
|
||||
PodRemovedFromVolume(podName volumetypes.UniquePodName, volumeName v1.UniqueVolumeName) bool
|
||||
|
||||
// VolumeExistsWithSpecName returns true if the given volume specified with the
|
||||
// volume spec name (a.k.a., InnerVolumeSpecName) exists in the list of
|
||||
// volumes that should be attached to this node.
|
||||
@ -686,6 +694,31 @@ func (asw *actualStateOfWorld) PodExistsInVolume(
|
||||
return podExists, volumeObj.devicePath, nil
|
||||
}
|
||||
|
||||
func (asw *actualStateOfWorld) PodRemovedFromVolume(
|
||||
podName volumetypes.UniquePodName,
|
||||
volumeName v1.UniqueVolumeName) bool {
|
||||
asw.RLock()
|
||||
defer asw.RUnlock()
|
||||
|
||||
volumeObj, volumeExists := asw.attachedVolumes[volumeName]
|
||||
if !volumeExists {
|
||||
return true
|
||||
}
|
||||
|
||||
podObj, podExists := volumeObj.mountedPods[podName]
|
||||
if podExists {
|
||||
// if volume mount was uncertain we should keep trying to unmount the volume
|
||||
if podObj.volumeMountStateForPod == operationexecutor.VolumeMountUncertain {
|
||||
return false
|
||||
}
|
||||
if podObj.volumeMountStateForPod == operationexecutor.VolumeMounted {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (asw *actualStateOfWorld) VolumeExistsWithSpecName(podName volumetypes.UniquePodName, volumeSpecName string) bool {
|
||||
asw.RLock()
|
||||
defer asw.RUnlock()
|
||||
|
@ -671,6 +671,10 @@ func TestUncertainVolumeMounts(t *testing.T) {
|
||||
if volExists {
|
||||
t.Fatalf("expected volume %s to not exist in asw", generatedVolumeName1)
|
||||
}
|
||||
removed := asw.PodRemovedFromVolume(podName1, generatedVolumeName1)
|
||||
if removed {
|
||||
t.Fatalf("expected volume %s not to be removed in asw", generatedVolumeName1)
|
||||
}
|
||||
}
|
||||
|
||||
func verifyVolumeExistsInGloballyMountedVolumes(
|
||||
|
@ -278,12 +278,12 @@ func (dswp *desiredStateOfWorldPopulator) findAndRemoveDeletedPods() {
|
||||
klog.V(4).InfoS("Pod still has one or more containers in the non-exited state and will not be removed from desired state", "pod", klog.KObj(volumeToMount.Pod))
|
||||
continue
|
||||
}
|
||||
exists, _, _ := dswp.actualStateOfWorld.PodExistsInVolume(volumeToMount.PodName, volumeToMount.VolumeName)
|
||||
var volumeToMountSpecName string
|
||||
if volumeToMount.VolumeSpec != nil {
|
||||
volumeToMountSpecName = volumeToMount.VolumeSpec.Name()
|
||||
}
|
||||
if !exists && podExists {
|
||||
removed := dswp.actualStateOfWorld.PodRemovedFromVolume(volumeToMount.PodName, volumeToMount.VolumeName)
|
||||
if removed && podExists {
|
||||
klog.V(4).InfoS("Actual state does not yet have volume mount information and pod still exists in pod manager, skip removing volume from desired state", "pod", klog.KObj(volumeToMount.Pod), "podUID", volumeToMount.Pod.UID, "volumeName", volumeToMountSpecName)
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user