From ed0facacfa4a2d9dacf85da7bfa53688af384f84 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Tue, 5 Dec 2023 15:49:51 -0500 Subject: [PATCH] Fix device uncertain errors on reboot --- pkg/kubelet/volumemanager/cache/actual_state_of_world.go | 5 +++++ pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go | 4 ++++ pkg/volume/util/operationexecutor/operation_executor.go | 5 +++++ pkg/volume/util/operationexecutor/operation_generator.go | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/pkg/kubelet/volumemanager/cache/actual_state_of_world.go b/pkg/kubelet/volumemanager/cache/actual_state_of_world.go index ada8c4415e4..3d449dcc0ee 100644 --- a/pkg/kubelet/volumemanager/cache/actual_state_of_world.go +++ b/pkg/kubelet/volumemanager/cache/actual_state_of_world.go @@ -414,6 +414,10 @@ func (asw *actualStateOfWorld) IsVolumeReconstructed(volumeName v1.UniqueVolumeN if !ok { return false } + + if podName == operationexecutor.EmptyUniquePodName { + return true + } _, foundPod := podMap[podName] return foundPod } @@ -810,6 +814,7 @@ func (asw *actualStateOfWorld) SetDeviceMountState( volumeObj.seLinuxMountContext = &seLinuxMountContext } } + asw.attachedVolumes[volumeName] = volumeObj return nil } diff --git a/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go b/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go index 2189d34991b..9968a09a24e 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go +++ b/pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go @@ -281,6 +281,10 @@ func TestReconstructVolumesMount(t *testing.T) { volumePath: filepath.Join("pod1uid", "volumes", "fake-plugin", volumetesting.FailOnSetupVolumeName), expectMount: false, }, + { + name: "reconstructed volume device map fails", + volumePath: filepath.Join("pod1uid", "volumeDevices", "fake-plugin", volumetesting.FailOnSetupVolumeName), + }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/volume/util/operationexecutor/operation_executor.go b/pkg/volume/util/operationexecutor/operation_executor.go index f4d257b005a..b4887357719 100644 --- a/pkg/volume/util/operationexecutor/operation_executor.go +++ b/pkg/volume/util/operationexecutor/operation_executor.go @@ -39,6 +39,11 @@ 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. diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index a8183572564..df05542e7a2 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -780,6 +780,11 @@ func (og *operationGenerator) checkForFailedMount(volumeToMount VolumeToMount, m func (og *operationGenerator) markDeviceErrorState(volumeToMount VolumeToMount, devicePath, deviceMountPath string, mountError error, actualStateOfWorld ActualStateOfWorldMounterUpdater) { 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) + return + } + // Only devices which were uncertain can be marked as unmounted markDeviceUnmountError := actualStateOfWorld.MarkDeviceAsUnmounted(volumeToMount.VolumeName) if markDeviceUnmountError != nil {