mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
kubelet: Fix the volume manager did't check the device mount state in the actual state of the world before marking the volume as detached. It may cause a pod to be stuck in the Terminating state due to the above issue when it was deleted.
This commit is contained in:
parent
9b2866fccb
commit
780ebfa496
@ -168,6 +168,11 @@ type ActualStateOfWorld interface {
|
|||||||
// or have a mount/unmount operation pending.
|
// or have a mount/unmount operation pending.
|
||||||
GetAttachedVolumes() []AttachedVolume
|
GetAttachedVolumes() []AttachedVolume
|
||||||
|
|
||||||
|
// GetAttachedVolume returns the volume that is known to be attached to the node
|
||||||
|
// with the given volume name. If the volume is not found, the second return value
|
||||||
|
// is false.
|
||||||
|
GetAttachedVolume(volumeName v1.UniqueVolumeName) (AttachedVolume, bool)
|
||||||
|
|
||||||
// SyncReconstructedVolume check the volume.outerVolumeSpecName in asw and
|
// SyncReconstructedVolume check the volume.outerVolumeSpecName in asw and
|
||||||
// the one populated from dsw, if they do not match, update this field from the value from dsw.
|
// the one populated from dsw, if they do not match, update this field from the value from dsw.
|
||||||
SyncReconstructedVolume(volumeName v1.UniqueVolumeName, podName volumetypes.UniquePodName, outerVolumeSpecName string)
|
SyncReconstructedVolume(volumeName v1.UniqueVolumeName, podName volumetypes.UniquePodName, outerVolumeSpecName string)
|
||||||
@ -1104,6 +1109,18 @@ func (asw *actualStateOfWorld) GetAttachedVolumes() []AttachedVolume {
|
|||||||
return allAttachedVolumes
|
return allAttachedVolumes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (asw *actualStateOfWorld) GetAttachedVolume(volumeName v1.UniqueVolumeName) (AttachedVolume, bool) {
|
||||||
|
asw.RLock()
|
||||||
|
defer asw.RUnlock()
|
||||||
|
|
||||||
|
volumeObj, ok := asw.attachedVolumes[volumeName]
|
||||||
|
if !ok {
|
||||||
|
return AttachedVolume{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return asw.newAttachedVolume(&volumeObj), true
|
||||||
|
}
|
||||||
|
|
||||||
func (asw *actualStateOfWorld) GetUnmountedVolumes() []AttachedVolume {
|
func (asw *actualStateOfWorld) GetUnmountedVolumes() []AttachedVolume {
|
||||||
asw.RLock()
|
asw.RLock()
|
||||||
defer asw.RUnlock()
|
defer asw.RUnlock()
|
||||||
|
@ -270,6 +270,11 @@ func (rc *reconciler) unmountDetachDevices() {
|
|||||||
// Check IsOperationPending to avoid marking a volume as detached if it's in the process of mounting.
|
// Check IsOperationPending to avoid marking a volume as detached if it's in the process of mounting.
|
||||||
if !rc.desiredStateOfWorld.VolumeExists(attachedVolume.VolumeName, attachedVolume.SELinuxMountContext) &&
|
if !rc.desiredStateOfWorld.VolumeExists(attachedVolume.VolumeName, attachedVolume.SELinuxMountContext) &&
|
||||||
!rc.operationExecutor.IsOperationPending(attachedVolume.VolumeName, nestedpendingoperations.EmptyUniquePodName, nestedpendingoperations.EmptyNodeName) {
|
!rc.operationExecutor.IsOperationPending(attachedVolume.VolumeName, nestedpendingoperations.EmptyUniquePodName, nestedpendingoperations.EmptyNodeName) {
|
||||||
|
|
||||||
|
// Re-read the actual state of the world, maybe the volume got mounted in the meantime.
|
||||||
|
// This is safe, because there is no pending operation (checked above) and no new operation
|
||||||
|
// could start in the meantime. The only goroutine that adds new operations is this reconciler.
|
||||||
|
attachedVolume, _ = rc.actualStateOfWorld.GetAttachedVolume(attachedVolume.VolumeName)
|
||||||
if attachedVolume.DeviceMayBeMounted() {
|
if attachedVolume.DeviceMayBeMounted() {
|
||||||
// Volume is globally mounted to device, unmount it
|
// Volume is globally mounted to device, unmount it
|
||||||
klog.V(5).InfoS(attachedVolume.GenerateMsgDetailed("Starting operationExecutor.UnmountDevice", ""))
|
klog.V(5).InfoS(attachedVolume.GenerateMsgDetailed("Starting operationExecutor.UnmountDevice", ""))
|
||||||
|
Loading…
Reference in New Issue
Block a user