diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler.go b/pkg/kubelet/volumemanager/reconciler/reconciler.go index 6a49bd36f7e..5ff538f4268 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconciler.go +++ b/pkg/kubelet/volumemanager/reconciler/reconciler.go @@ -493,32 +493,12 @@ func (rc *reconciler) reconstructVolume(volume podVolume) (*reconstructedVolume, uniqueVolumeName = util.GetUniqueVolumeNameFromSpecWithPod(volume.podName, plugin, volumeSpec) } - volumeMounter, newMounterErr := plugin.NewMounter( - volumeSpec, - pod, - volumepkg.VolumeOptions{}) - if newMounterErr != nil { - return nil, fmt.Errorf( - "reconstructVolume.NewMounter failed for volume %q (spec.Name: %q) pod %q (UID: %q) with: %v", - uniqueVolumeName, - volumeSpec.Name(), - volume.podName, - pod.UID, - newMounterErr) - } - - // Check existence of mount point for filesystem volume or symbolic link for block volume - isExist, checkErr := rc.operationExecutor.CheckVolumeExistenceOperation(volumeSpec, volumeMounter.GetPath(), volumeSpec.Name(), rc.mounter, uniqueVolumeName, volume.podName, pod.UID, attachablePlugin) - if checkErr != nil { - return nil, checkErr - } - // If mount or symlink doesn't exist, volume reconstruction should be failed - if !isExist { - return nil, fmt.Errorf("Volume: %q is not mounted", uniqueVolumeName) - } + var volumeMapper volumepkg.BlockVolumeMapper + var volumeMounter volumepkg.Mounter + // Path to the mount or block device to check + var checkPath string // TODO: remove feature gate check after no longer needed - var volumeMapper volumepkg.BlockVolumeMapper if utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && volume.volumeMode == v1.PersistentVolumeBlock { var newMapperErr error if mapperPlugin != nil { @@ -535,7 +515,34 @@ func (rc *reconciler) reconstructVolume(volume podVolume) (*reconstructedVolume, pod.UID, newMapperErr) } + checkPath, _ = volumeMapper.GetPodDeviceMapPath() } + } else { + var err error + volumeMounter, err = plugin.NewMounter( + volumeSpec, + pod, + volumepkg.VolumeOptions{}) + if err != nil { + return nil, fmt.Errorf( + "reconstructVolume.NewMounter failed for volume %q (spec.Name: %q) pod %q (UID: %q) with: %v", + uniqueVolumeName, + volumeSpec.Name(), + volume.podName, + pod.UID, + err) + } + checkPath = volumeMounter.GetPath() + } + + // Check existence of mount point for filesystem volume or symbolic link for block volume + isExist, checkErr := rc.operationExecutor.CheckVolumeExistenceOperation(volumeSpec, checkPath, volumeSpec.Name(), rc.mounter, uniqueVolumeName, volume.podName, pod.UID, attachablePlugin) + if checkErr != nil { + return nil, checkErr + } + // If mount or symlink doesn't exist, volume reconstruction should be failed + if !isExist { + return nil, fmt.Errorf("Volume: %q is not mounted", uniqueVolumeName) } reconstructedVolume := &reconstructedVolume{ diff --git a/pkg/volume/util/operationexecutor/operation_executor.go b/pkg/volume/util/operationexecutor/operation_executor.go index 8e059dc11f0..0d6cb623b70 100644 --- a/pkg/volume/util/operationexecutor/operation_executor.go +++ b/pkg/volume/util/operationexecutor/operation_executor.go @@ -543,10 +543,12 @@ type MountedVolume struct { // Mounter is the volume mounter used to mount this volume. It is required // by kubelet to create container.VolumeMap. + // Mounter is only required for file system volumes and not required for block volumes. Mounter volume.Mounter // BlockVolumeMapper is the volume mapper used to map this volume. It is required // by kubelet to create container.VolumeMap. + // BlockVolumeMapper is only required for block volumes and not required for file system volumes. BlockVolumeMapper volume.BlockVolumeMapper // VolumeGidValue contains the value of the GID annotation, if present. @@ -935,6 +937,9 @@ func (oe *operationExecutor) CheckVolumeExistenceOperation( if attachable != nil { var isNotMount bool var mountCheckErr error + if mounter == nil { + return false, fmt.Errorf("mounter was not set for a filesystem volume") + } if isNotMount, mountCheckErr = mounter.IsLikelyNotMountPoint(mountPath); mountCheckErr != nil { return false, fmt.Errorf("Could not check whether the volume %q (spec.Name: %q) pod %q (UID: %q) is mounted with: %v", uniqueVolumeName,