diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 120191488a4..269c8b51636 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -669,6 +669,16 @@ func (og *operationGenerator) GenerateMountVolumeFunc( resizeOptions.DeviceStagePath = deviceMountPath } + if volumeDeviceMounter != nil && resizeOptions.DeviceStagePath == "" { + deviceStagePath, err := volumeDeviceMounter.GetDeviceMountPath(volumeToMount.VolumeSpec) + if err != nil { + // On failure, return error. Caller will log and retry. + eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.GetDeviceMountPath failed for expansion", err) + return volumetypes.NewOperationContext(eventErr, detailedErr, migrated) + } + resizeOptions.DeviceStagePath = deviceStagePath + } + // No mapping is needed for hostUID/hostGID if userns is not used. // Therefore, just assign the container users to host UID/GID. hostUID := util.FsUserFrom(volumeToMount.Pod) diff --git a/test/e2e/storage/csi_mock/csi_volume_expansion.go b/test/e2e/storage/csi_mock/csi_volume_expansion.go index 2cdf43d4395..95921fb1e7f 100644 --- a/test/e2e/storage/csi_mock/csi_volume_expansion.go +++ b/test/e2e/storage/csi_mock/csi_volume_expansion.go @@ -46,6 +46,7 @@ const ( expansionFailed expansionFailedOnController expansionFailedOnNode + expansionFailedMissingStagingPath ) const ( @@ -78,25 +79,35 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() { nodeExpansionRequired bool disableAttach bool disableResizingOnDriver bool + simulatedCSIDriverError expansionStatus expectFailure bool }{ { - name: "should expand volume without restarting pod if nodeExpansion=off", - nodeExpansionRequired: false, + name: "should expand volume without restarting pod if nodeExpansion=off", + nodeExpansionRequired: false, + simulatedCSIDriverError: expansionSuccess, }, { - name: "should expand volume by restarting pod if attach=on, nodeExpansion=on", - nodeExpansionRequired: true, + name: "should expand volume by restarting pod if attach=on, nodeExpansion=on", + nodeExpansionRequired: true, + simulatedCSIDriverError: expansionSuccess, }, { - name: "should expand volume by restarting pod if attach=off, nodeExpansion=on", - disableAttach: true, - nodeExpansionRequired: true, + name: "should not have staging_path missing in node expand volume pod if attach=on, nodeExpansion=on", + nodeExpansionRequired: true, + simulatedCSIDriverError: expansionFailedMissingStagingPath, + }, + { + name: "should expand volume by restarting pod if attach=off, nodeExpansion=on", + disableAttach: true, + nodeExpansionRequired: true, + simulatedCSIDriverError: expansionSuccess, }, { name: "should not expand volume if resizingOnDriver=off, resizingOnSC=on", disableResizingOnDriver: true, expectFailure: true, + simulatedCSIDriverError: expansionSuccess, }, } for _, t := range tests { @@ -113,6 +124,7 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() { tp.disableAttach = true tp.registerDriver = true } + tp.hooks = createExpansionHook(test.simulatedCSIDriverError) m.init(ctx, tp) ginkgo.DeferCleanup(m.cleanup) @@ -172,8 +184,12 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() { } ginkgo.By("Deleting the previously created pod") - err = e2epod.DeletePodWithWait(ctx, m.cs, pod) - framework.ExpectNoError(err, "while deleting pod for resizing") + if test.simulatedCSIDriverError == expansionFailedMissingStagingPath { + e2epod.DeletePodOrFail(ctx, m.cs, pod.Namespace, pod.Name) + } else { + err = e2epod.DeletePodWithWait(ctx, m.cs, pod) + framework.ExpectNoError(err, "while deleting pod for resizing") + } ginkgo.By("Creating a new pod with same volume") pod2, err := m.createPodWithPVC(pvc) @@ -445,6 +461,15 @@ func createExpansionHook(expectedExpansionStatus expansionStatus) *drivers.Hooks return &drivers.Hooks{ Pre: func(ctx context.Context, method string, request interface{}) (reply interface{}, err error) { switch expectedExpansionStatus { + case expansionFailedMissingStagingPath: + expansionRequest, ok := request.(*csipbv1.NodeExpandVolumeRequest) + if ok { + stagingPath := expansionRequest.StagingTargetPath + if stagingPath == "" { + return nil, status.Error(codes.InvalidArgument, "invalid node expansion request, missing staging path") + } + + } case expansionFailedOnController: expansionRequest, ok := request.(*csipbv1.ControllerExpandVolumeRequest) if ok {