Merge pull request #115346 from gnufied/set-staging-path-expansion

Set node_stage_path whenever available
This commit is contained in:
Kubernetes Prow Robot 2023-01-30 21:38:47 -08:00 committed by GitHub
commit f9a3fd2810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 9 deletions

View File

@ -669,6 +669,16 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
resizeOptions.DeviceStagePath = deviceMountPath 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. // No mapping is needed for hostUID/hostGID if userns is not used.
// Therefore, just assign the container users to host UID/GID. // Therefore, just assign the container users to host UID/GID.
hostUID := util.FsUserFrom(volumeToMount.Pod) hostUID := util.FsUserFrom(volumeToMount.Pod)

View File

@ -46,6 +46,7 @@ const (
expansionFailed expansionFailed
expansionFailedOnController expansionFailedOnController
expansionFailedOnNode expansionFailedOnNode
expansionFailedMissingStagingPath
) )
const ( const (
@ -78,25 +79,35 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() {
nodeExpansionRequired bool nodeExpansionRequired bool
disableAttach bool disableAttach bool
disableResizingOnDriver bool disableResizingOnDriver bool
simulatedCSIDriverError expansionStatus
expectFailure bool expectFailure bool
}{ }{
{ {
name: "should expand volume without restarting pod if nodeExpansion=off", name: "should expand volume without restarting pod if nodeExpansion=off",
nodeExpansionRequired: false, nodeExpansionRequired: false,
simulatedCSIDriverError: expansionSuccess,
}, },
{ {
name: "should expand volume by restarting pod if attach=on, nodeExpansion=on", name: "should expand volume by restarting pod if attach=on, nodeExpansion=on",
nodeExpansionRequired: true, nodeExpansionRequired: true,
simulatedCSIDriverError: expansionSuccess,
}, },
{ {
name: "should expand volume by restarting pod if attach=off, nodeExpansion=on", name: "should not have staging_path missing in node expand volume pod if attach=on, nodeExpansion=on",
disableAttach: true, nodeExpansionRequired: true,
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", name: "should not expand volume if resizingOnDriver=off, resizingOnSC=on",
disableResizingOnDriver: true, disableResizingOnDriver: true,
expectFailure: true, expectFailure: true,
simulatedCSIDriverError: expansionSuccess,
}, },
} }
for _, t := range tests { for _, t := range tests {
@ -113,6 +124,7 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() {
tp.disableAttach = true tp.disableAttach = true
tp.registerDriver = true tp.registerDriver = true
} }
tp.hooks = createExpansionHook(test.simulatedCSIDriverError)
m.init(ctx, tp) m.init(ctx, tp)
ginkgo.DeferCleanup(m.cleanup) ginkgo.DeferCleanup(m.cleanup)
@ -172,8 +184,12 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() {
} }
ginkgo.By("Deleting the previously created pod") ginkgo.By("Deleting the previously created pod")
err = e2epod.DeletePodWithWait(ctx, m.cs, pod) if test.simulatedCSIDriverError == expansionFailedMissingStagingPath {
framework.ExpectNoError(err, "while deleting pod for resizing") 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") ginkgo.By("Creating a new pod with same volume")
pod2, err := m.createPodWithPVC(pvc) pod2, err := m.createPodWithPVC(pvc)
@ -445,6 +461,15 @@ func createExpansionHook(expectedExpansionStatus expansionStatus) *drivers.Hooks
return &drivers.Hooks{ return &drivers.Hooks{
Pre: func(ctx context.Context, method string, request interface{}) (reply interface{}, err error) { Pre: func(ctx context.Context, method string, request interface{}) (reply interface{}, err error) {
switch expectedExpansionStatus { 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: case expansionFailedOnController:
expansionRequest, ok := request.(*csipbv1.ControllerExpandVolumeRequest) expansionRequest, ok := request.(*csipbv1.ControllerExpandVolumeRequest)
if ok { if ok {