From e706b6ba14b5460e6ddc0c2bedc1cdb3639d8666 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 13 Dec 2023 10:18:57 -0500 Subject: [PATCH] Use a separate function for checking if device was reconstructed --- .../volumemanager/cache/actual_state_of_world.go | 13 ++++++++----- .../util/operationexecutor/operation_executor.go | 9 ++++----- .../util/operationexecutor/operation_generator.go | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/kubelet/volumemanager/cache/actual_state_of_world.go b/pkg/kubelet/volumemanager/cache/actual_state_of_world.go index ebc7869fd1f..f0e53131499 100644 --- a/pkg/kubelet/volumemanager/cache/actual_state_of_world.go +++ b/pkg/kubelet/volumemanager/cache/actual_state_of_world.go @@ -404,7 +404,7 @@ func (asw *actualStateOfWorld) IsVolumeReconstructed(volumeName v1.UniqueVolumeN volumeState := asw.GetVolumeMountState(volumeName, podName) // only uncertain volumes are reconstructed - if volumeState != operationexecutor.VolumeMountUncertain && podName != operationexecutor.EmptyUniquePodName { + if volumeState != operationexecutor.VolumeMountUncertain { return false } @@ -414,14 +414,17 @@ func (asw *actualStateOfWorld) IsVolumeReconstructed(volumeName v1.UniqueVolumeN if !ok { return false } - - if podName == operationexecutor.EmptyUniquePodName { - return true - } _, foundPod := podMap[podName] return foundPod } +func (asw *actualStateOfWorld) IsVolumeDeviceReconstructed(volumeName v1.UniqueVolumeName) bool { + asw.RLock() + defer asw.RUnlock() + _, ok := asw.foundDuringReconstruction[volumeName] + return ok +} + func (asw *actualStateOfWorld) CheckAndMarkVolumeAsUncertainViaReconstruction(opts operationexecutor.MarkVolumeOpts) (bool, error) { asw.Lock() defer asw.Unlock() diff --git a/pkg/volume/util/operationexecutor/operation_executor.go b/pkg/volume/util/operationexecutor/operation_executor.go index b4887357719..0fa04e427e4 100644 --- a/pkg/volume/util/operationexecutor/operation_executor.go +++ b/pkg/volume/util/operationexecutor/operation_executor.go @@ -39,11 +39,6 @@ import ( volumetypes "k8s.io/kubernetes/pkg/volume/util/types" ) -const ( - // EmptyUniquePodName is a UniquePodName for empty string. - EmptyUniquePodName volumetypes.UniquePodName = volumetypes.UniquePodName("") -) - // OperationExecutor defines a set of operations for attaching, detaching, // mounting, or unmounting a volume that are executed with a NewNestedPendingOperations which // prevents more than one operation from being triggered on the same volume. @@ -234,6 +229,10 @@ type ActualStateOfWorldMounterUpdater interface { // IsVolumeReconstructed returns true if volume currently added to actual state of the world // was found during reconstruction. IsVolumeReconstructed(volumeName v1.UniqueVolumeName, podName volumetypes.UniquePodName) bool + + // IsVolumeDeviceReconstructed returns true if volume device identified by volumeName has been + // found during reconstruction. + IsVolumeDeviceReconstructed(volumeName v1.UniqueVolumeName) bool } // ActualStateOfWorldAttacherUpdater defines a set of operations updating the diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 68082507312..c880aa54cda 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -781,8 +781,8 @@ func (og *operationGenerator) markDeviceErrorState(volumeToMount VolumeToMount, if volumetypes.IsOperationFinishedError(mountError) && actualStateOfWorld.GetDeviceMountState(volumeToMount.VolumeName) == DeviceMountUncertain { - if actualStateOfWorld.IsVolumeReconstructed(volumeToMount.VolumeName, EmptyUniquePodName) { - klog.V(2).InfoS("MountVolume.markDeviceErrorState uncertainDeviceFix leaving volume uncertain", "volumeName", volumeToMount.VolumeName) + if actualStateOfWorld.IsVolumeDeviceReconstructed(volumeToMount.VolumeName) { + klog.V(2).InfoS("MountVolume.markDeviceErrorState leaving volume uncertain", "volumeName", volumeToMount.VolumeName) return }