diff --git a/pkg/volume/csi/csi_client.go b/pkg/volume/csi/csi_client.go index 8483ca651d2..d3d474f2942 100644 --- a/pkg/volume/csi/csi_client.go +++ b/pkg/volume/csi/csi_client.go @@ -113,11 +113,7 @@ type csiDriverClient struct { } type csiResizeOptions struct { - volumeID string - // volumePath is path where volume is available. It could be: - // - path where node is staged if NodeExpandVolume is called after NodeStageVolume - // - path where volume is published if NodeExpandVolume is called after NodePublishVolume - // DEPRECATION NOTICE: in future NodeExpandVolume will be always called after NodePublish + volumeID string volumePath string stagingTargetPath string fsType string diff --git a/pkg/volume/csi/expander.go b/pkg/volume/csi/expander.go index 0d4e9b26d26..58594a5bfdc 100644 --- a/pkg/volume/csi/expander.go +++ b/pkg/volume/csi/expander.go @@ -82,20 +82,6 @@ func (c *csiPlugin) nodeExpandWithClient( return false, fmt.Errorf("Expander.NodeExpand found CSI plugin %s/%s to not support node expansion", c.GetPluginName(), driverName) } - // Check whether "STAGE_UNSTAGE_VOLUME" is set - stageUnstageSet, err := csClient.NodeSupportsStageUnstage(ctx) - if err != nil { - return false, fmt.Errorf("Expander.NodeExpand failed to check if plugins supports stage_unstage %v", err) - } - - // if plugin does not support STAGE_UNSTAGE but CSI volume path is staged - // it must mean this was placeholder staging performed by k8s and not CSI staging - // in which case we should return from here so as volume can be node published - // before we can resize - if !stageUnstageSet && resizeOptions.CSIVolumePhase == volume.CSIVolumeStaged { - return false, nil - } - pv := resizeOptions.VolumeSpec.PersistentVolume if pv == nil { return false, fmt.Errorf("Expander.NodeExpand failed to find associated PersistentVolume for plugin %s", c.GetPluginName()) diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index e857a67b704..106b3ee47d8 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -634,7 +634,6 @@ func (og *operationGenerator) GenerateMountVolumeFunc( klog.InfoS(volumeToMount.GenerateMsgDetailed("MountVolume.WaitForAttach succeeded", fmt.Sprintf("DevicePath %q", devicePath)), "pod", klog.KObj(volumeToMount.Pod)) } - var resizeDone bool var resizeError error resizeOptions := volume.NodeResizeOptions{ DevicePath: devicePath, @@ -674,35 +673,8 @@ func (og *operationGenerator) GenerateMountVolumeFunc( eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.MarkDeviceAsMounted failed", markDeviceMountedErr) return volumetypes.NewOperationContext(eventErr, detailedErr, migrated) } - - // If volume expansion is performed after MountDevice but before SetUp then - // deviceMountPath and deviceStagePath is going to be the same. - // Deprecation: Calling NodeExpandVolume after NodeStage/MountDevice will be deprecated - // in a future version of k8s. - resizeOptions.DeviceMountPath = deviceMountPath + // set staging path for volume expansion resizeOptions.DeviceStagePath = deviceMountPath - resizeOptions.CSIVolumePhase = volume.CSIVolumeStaged - - // NodeExpandVolume will resize the file system if user has requested a resize of - // underlying persistent volume and is allowed to do so. - resizeDone, resizeError = og.nodeExpandVolume(volumeToMount, actualStateOfWorld, resizeOptions) - - if resizeError != nil { - klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError) - - // Resize failed. To make sure NodeExpand is re-tried again on the next attempt - // *before* SetUp(), mark the mounted device as uncertain. - markDeviceUncertainErr := actualStateOfWorld.MarkDeviceAsUncertain( - volumeToMount.VolumeName, devicePath, deviceMountPath) - if markDeviceUncertainErr != nil { - // just log, return the resizeError error instead - klog.InfoS(volumeToMount.GenerateMsgDetailed( - "MountVolume.MountDevice failed to mark volume as uncertain", - markDeviceUncertainErr.Error()), "pod", klog.KObj(volumeToMount.Pod)) - } - eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.MountDevice failed while expanding volume", resizeError) - return volumetypes.NewOperationContext(eventErr, detailedErr, migrated) - } } // Execute mount @@ -740,25 +712,19 @@ func (og *operationGenerator) GenerateMountVolumeFunc( resizeOptions.DeviceMountPath = volumeMounter.GetPath() resizeOptions.CSIVolumePhase = volume.CSIVolumePublished - // We need to call resizing here again in case resizing was not done during device mount. There could be - // two reasons of that: - // - Volume does not support DeviceMounter interface. - // - In case of CSI the volume does not have node stage_unstage capability. - if !resizeDone { - _, resizeError = og.nodeExpandVolume(volumeToMount, actualStateOfWorld, resizeOptions) - if resizeError != nil { - klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError) - eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.Setup failed while expanding volume", resizeError) - // At this point, MountVolume.Setup already succeeded, we should add volume into actual state - // so that reconciler can clean up volume when needed. However, volume resize failed, - // we should not mark the volume as mounted to avoid pod starts using it. - // Considering the above situations, we mark volume as uncertain here so that reconciler will tigger - // volume tear down when pod is deleted, and also makes sure pod will not start using it. - if err := actualStateOfWorld.MarkVolumeMountAsUncertain(markOpts); err != nil { - klog.Errorf(volumeToMount.GenerateErrorDetailed("MountVolume.MarkVolumeMountAsUncertain failed", err).Error()) - } - return volumetypes.NewOperationContext(eventErr, detailedErr, migrated) + _, resizeError = og.nodeExpandVolume(volumeToMount, actualStateOfWorld, resizeOptions) + if resizeError != nil { + klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError) + eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.Setup failed while expanding volume", resizeError) + // At this point, MountVolume.Setup already succeeded, we should add volume into actual state + // so that reconciler can clean up volume when needed. However, volume resize failed, + // we should not mark the volume as mounted to avoid pod starts using it. + // Considering the above situations, we mark volume as uncertain here so that reconciler will tigger + // volume tear down when pod is deleted, and also makes sure pod will not start using it. + if err := actualStateOfWorld.MarkVolumeMountAsUncertain(markOpts); err != nil { + klog.Errorf(volumeToMount.GenerateErrorDetailed("MountVolume.MarkVolumeMountAsUncertain failed", err).Error()) } + return volumetypes.NewOperationContext(eventErr, detailedErr, migrated) } // record total time it takes to mount a volume. This is end to end time that includes waiting for volume to attach, node to be update