diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler.go b/pkg/kubelet/volumemanager/reconciler/reconciler.go index a342d58ba9b..514f0139c15 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconciler.go +++ b/pkg/kubelet/volumemanager/reconciler/reconciler.go @@ -765,7 +765,7 @@ func (rc *reconciler) markVolumeState(volume *reconstructedVolume, volumeState o OuterVolumeSpecName: volume.outerVolumeSpecName, VolumeGidVolume: volume.volumeGidValue, VolumeSpec: volume.volumeSpec, - VolumeMountState: operationexecutor.VolumeMounted, + VolumeMountState: volumeState, } err := rc.actualStateOfWorld.MarkVolumeAsMounted(markVolumeOpts) return err diff --git a/pkg/volume/util/operationexecutor/operation_executor.go b/pkg/volume/util/operationexecutor/operation_executor.go index 4f0e8cb9e0a..541d86e2ace 100644 --- a/pkg/volume/util/operationexecutor/operation_executor.go +++ b/pkg/volume/util/operationexecutor/operation_executor.go @@ -216,8 +216,12 @@ type ActualStateOfWorldMounterUpdater interface { // volume expansion must not be retried for this volume MarkForInUseExpansionError(volumeName v1.UniqueVolumeName) + // AddVolumeViaReconstruction adds the volume to actual state of the world and also + // marks the volume as one found during reconstruction. AddVolumeViaReconstruction(opts MarkVolumeOpts) error + // 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 } diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 90404714b93..71ca9ce40d5 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -784,13 +784,20 @@ func (og *operationGenerator) markDeviceErrorState(volumeToMount VolumeToMount, func (og *operationGenerator) markVolumeErrorState(volumeToMount VolumeToMount, markOpts MarkVolumeOpts, mountError error, actualStateOfWorld ActualStateOfWorldMounterUpdater) { if volumetypes.IsOperationFinishedError(mountError) && - actualStateOfWorld.GetVolumeMountState(volumeToMount.VolumeName, markOpts.PodName) == VolumeMountUncertain && - !actualStateOfWorld.IsVolumeReconstructed(volumeToMount.VolumeName, volumeToMount.PodName) { + actualStateOfWorld.GetVolumeMountState(volumeToMount.VolumeName, markOpts.PodName) == VolumeMountUncertain { + // if volume was previously reconstructed we are not going to change its state as unmounted even + // if mount operation fails. + if actualStateOfWorld.IsVolumeReconstructed(volumeToMount.VolumeName, volumeToMount.PodName) { + klog.V(3).Infof("MountVolume.markVolumeErrorState leaving volume uncertain", "volumeName", volumeToMount.VolumeName) + return + } + t := actualStateOfWorld.MarkVolumeAsUnmounted(volumeToMount.PodName, volumeToMount.VolumeName) if t != nil { klog.Errorf(volumeToMount.GenerateErrorDetailed("MountVolume.MarkVolumeAsUnmounted failed", t).Error()) } return + } if volumetypes.IsUncertainProgressError(mountError) &&