From 75e13e370e48a0880ad7ab46191723f9f150cebc Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Mon, 16 Mar 2020 16:38:00 -0400 Subject: [PATCH] Supply staging path for block expansion --- pkg/volume/csi/csi_block.go | 20 +++++++++---------- pkg/volume/csi/csi_block_test.go | 3 +-- pkg/volume/local/local.go | 4 ++-- .../operationexecutor/operation_generator.go | 9 ++++++--- pkg/volume/volume.go | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pkg/volume/csi/csi_block.go b/pkg/volume/csi/csi_block.go index da14ea9b5cc..6903add1d8e 100644 --- a/pkg/volume/csi/csi_block.go +++ b/pkg/volume/csi/csi_block.go @@ -255,26 +255,26 @@ func (m *csiBlockMapper) publishVolumeForBlock( } // SetUpDevice ensures the device is attached returns path where the device is located. -func (m *csiBlockMapper) SetUpDevice() error { +func (m *csiBlockMapper) SetUpDevice() (string, error) { if !m.plugin.blockEnabled { - return errors.New("CSIBlockVolume feature not enabled") + return "", errors.New("CSIBlockVolume feature not enabled") } klog.V(4).Infof(log("blockMapper.SetUpDevice called")) // Get csiSource from spec if m.spec == nil { - return errors.New(log("blockMapper.SetUpDevice spec is nil")) + return "", errors.New(log("blockMapper.SetUpDevice spec is nil")) } csiSource, err := getCSISourceFromSpec(m.spec) if err != nil { - return errors.New(log("blockMapper.SetUpDevice failed to get CSI persistent source: %v", err)) + return "", errors.New(log("blockMapper.SetUpDevice failed to get CSI persistent source: %v", err)) } driverName := csiSource.Driver skip, err := m.plugin.skipAttach(driverName) if err != nil { - return errors.New(log("blockMapper.SetupDevice failed to check CSIDriver for %s: %v", driverName, err)) + return "", errors.New(log("blockMapper.SetupDevice failed to check CSIDriver for %s: %v", driverName, err)) } var attachment *storage.VolumeAttachment @@ -284,7 +284,7 @@ func (m *csiBlockMapper) SetUpDevice() error { attachID := getAttachmentName(csiSource.VolumeHandle, csiSource.Driver, nodeName) attachment, err = m.k8s.StorageV1().VolumeAttachments().Get(context.TODO(), attachID, meta.GetOptions{}) if err != nil { - return errors.New(log("blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v", attachID, err)) + return "", errors.New(log("blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v", attachID, err)) } } @@ -299,11 +299,11 @@ func (m *csiBlockMapper) SetUpDevice() error { csiClient, err := m.csiClientGetter.Get() if err != nil { - return errors.New(log("blockMapper.SetUpDevice failed to get CSI client: %v", err)) + return "", errors.New(log("blockMapper.SetUpDevice failed to get CSI client: %v", err)) } // Call NodeStageVolume - _, err = m.stageVolumeForBlock(ctx, csiClient, accessMode, csiSource, attachment) + stagingPath, err := m.stageVolumeForBlock(ctx, csiClient, accessMode, csiSource, attachment) if err != nil { if volumetypes.IsOperationFinishedError(err) { cleanupErr := m.cleanupOrphanDeviceFiles() @@ -312,10 +312,10 @@ func (m *csiBlockMapper) SetUpDevice() error { klog.V(4).Infof("Failed to clean up block volume directory %s", cleanupErr) } } - return err + return "", err } - return nil + return stagingPath, nil } func (m *csiBlockMapper) MapPodDevice() (string, error) { diff --git a/pkg/volume/csi/csi_block_test.go b/pkg/volume/csi/csi_block_test.go index ccc8d6faf5c..47be8f3303a 100644 --- a/pkg/volume/csi/csi_block_test.go +++ b/pkg/volume/csi/csi_block_test.go @@ -234,13 +234,12 @@ func TestBlockMapperSetupDevice(t *testing.T) { } t.Log("created attachement ", attachID) - err = csiMapper.SetUpDevice() + stagingPath, err := csiMapper.SetUpDevice() if err != nil { t.Fatalf("mapper failed to SetupDevice: %v", err) } // Check if NodeStageVolume staged to the right path - stagingPath := csiMapper.getStagingPath() svols := csiMapper.csiClient.(*fakeCsiDriverClient).nodeClient.GetNodeStagedVolumes() svol, ok := svols[csiMapper.volumeID] if !ok { diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index 09ec2f202c8..18bb72b46b3 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -610,8 +610,8 @@ var _ volume.BlockVolumeMapper = &localVolumeMapper{} var _ volume.CustomBlockVolumeMapper = &localVolumeMapper{} // SetUpDevice prepares the volume to the node by the plugin specific way. -func (m *localVolumeMapper) SetUpDevice() error { - return nil +func (m *localVolumeMapper) SetUpDevice() (string, error) { + return "", nil } // MapPodDevice provides physical device path for the local PV. diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 76a50a457f6..6ee6e865570 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -947,6 +947,7 @@ func (og *operationGenerator) GenerateMapVolumeFunc( mapVolumeFunc := func() (simpleErr error, detailedErr error) { var devicePath string + var stagingPath string // Set up global map path under the given plugin directory using symbolic link globalMapPath, err := blockVolumeMapper.GetGlobalMapPath(volumeToMount.VolumeSpec) @@ -970,7 +971,8 @@ func (og *operationGenerator) GenerateMapVolumeFunc( } // Call SetUpDevice if blockVolumeMapper implements CustomBlockVolumeMapper if customBlockVolumeMapper, ok := blockVolumeMapper.(volume.CustomBlockVolumeMapper); ok { - mapErr := customBlockVolumeMapper.SetUpDevice() + var mapErr error + stagingPath, mapErr = customBlockVolumeMapper.SetUpDevice() if mapErr != nil { og.markDeviceErrorState(volumeToMount, devicePath, globalMapPath, mapErr, actualStateOfWorld) // On failure, return error. Caller will log and retry. @@ -1073,8 +1075,9 @@ func (og *operationGenerator) GenerateMapVolumeFunc( klog.V(verbosity).Infof(detailedMsg) resizeOptions := volume.NodeResizeOptions{ - DevicePath: devicePath, - CSIVolumePhase: volume.CSIVolumePublished, + DevicePath: devicePath, + DeviceStagePath: stagingPath, + CSIVolumePhase: volume.CSIVolumePublished, } _, resizeError := og.nodeExpandVolume(volumeToMount, resizeOptions) if resizeError != nil { diff --git a/pkg/volume/volume.go b/pkg/volume/volume.go index 9a2f08403d4..1f36d1e17de 100644 --- a/pkg/volume/volume.go +++ b/pkg/volume/volume.go @@ -174,7 +174,7 @@ type CustomBlockVolumeMapper interface { // For most in-tree plugins, attacher.Attach() and attacher.WaitForAttach() // will do necessary works. // This may be called more than once, so implementations must be idempotent. - SetUpDevice() error + SetUpDevice() (string, error) // MapPodDevice maps the block device to a path and return the path. // Unique device path across kubelet node reboot is required to avoid