Skip to content

Commit 75e13e3

Browse files
committed
Supply staging path for block expansion
1 parent 7d6959c commit 75e13e3

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

pkg/volume/csi/csi_block.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,26 +255,26 @@ func (m *csiBlockMapper) publishVolumeForBlock(
255255
}
256256

257257
// SetUpDevice ensures the device is attached returns path where the device is located.
258-
func (m *csiBlockMapper) SetUpDevice() error {
258+
func (m *csiBlockMapper) SetUpDevice() (string, error) {
259259
if !m.plugin.blockEnabled {
260-
return errors.New("CSIBlockVolume feature not enabled")
260+
return "", errors.New("CSIBlockVolume feature not enabled")
261261
}
262262
klog.V(4).Infof(log("blockMapper.SetUpDevice called"))
263263

264264
// Get csiSource from spec
265265
if m.spec == nil {
266-
return errors.New(log("blockMapper.SetUpDevice spec is nil"))
266+
return "", errors.New(log("blockMapper.SetUpDevice spec is nil"))
267267
}
268268

269269
csiSource, err := getCSISourceFromSpec(m.spec)
270270
if err != nil {
271-
return errors.New(log("blockMapper.SetUpDevice failed to get CSI persistent source: %v", err))
271+
return "", errors.New(log("blockMapper.SetUpDevice failed to get CSI persistent source: %v", err))
272272
}
273273

274274
driverName := csiSource.Driver
275275
skip, err := m.plugin.skipAttach(driverName)
276276
if err != nil {
277-
return errors.New(log("blockMapper.SetupDevice failed to check CSIDriver for %s: %v", driverName, err))
277+
return "", errors.New(log("blockMapper.SetupDevice failed to check CSIDriver for %s: %v", driverName, err))
278278
}
279279

280280
var attachment *storage.VolumeAttachment
@@ -284,7 +284,7 @@ func (m *csiBlockMapper) SetUpDevice() error {
284284
attachID := getAttachmentName(csiSource.VolumeHandle, csiSource.Driver, nodeName)
285285
attachment, err = m.k8s.StorageV1().VolumeAttachments().Get(context.TODO(), attachID, meta.GetOptions{})
286286
if err != nil {
287-
return errors.New(log("blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v", attachID, err))
287+
return "", errors.New(log("blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v", attachID, err))
288288
}
289289
}
290290

@@ -299,11 +299,11 @@ func (m *csiBlockMapper) SetUpDevice() error {
299299

300300
csiClient, err := m.csiClientGetter.Get()
301301
if err != nil {
302-
return errors.New(log("blockMapper.SetUpDevice failed to get CSI client: %v", err))
302+
return "", errors.New(log("blockMapper.SetUpDevice failed to get CSI client: %v", err))
303303
}
304304

305305
// Call NodeStageVolume
306-
_, err = m.stageVolumeForBlock(ctx, csiClient, accessMode, csiSource, attachment)
306+
stagingPath, err := m.stageVolumeForBlock(ctx, csiClient, accessMode, csiSource, attachment)
307307
if err != nil {
308308
if volumetypes.IsOperationFinishedError(err) {
309309
cleanupErr := m.cleanupOrphanDeviceFiles()
@@ -312,10 +312,10 @@ func (m *csiBlockMapper) SetUpDevice() error {
312312
klog.V(4).Infof("Failed to clean up block volume directory %s", cleanupErr)
313313
}
314314
}
315-
return err
315+
return "", err
316316
}
317317

318-
return nil
318+
return stagingPath, nil
319319
}
320320

321321
func (m *csiBlockMapper) MapPodDevice() (string, error) {

pkg/volume/csi/csi_block_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,12 @@ func TestBlockMapperSetupDevice(t *testing.T) {
234234
}
235235
t.Log("created attachement ", attachID)
236236

237-
err = csiMapper.SetUpDevice()
237+
stagingPath, err := csiMapper.SetUpDevice()
238238
if err != nil {
239239
t.Fatalf("mapper failed to SetupDevice: %v", err)
240240
}
241241

242242
// Check if NodeStageVolume staged to the right path
243-
stagingPath := csiMapper.getStagingPath()
244243
svols := csiMapper.csiClient.(*fakeCsiDriverClient).nodeClient.GetNodeStagedVolumes()
245244
svol, ok := svols[csiMapper.volumeID]
246245
if !ok {

pkg/volume/local/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ var _ volume.BlockVolumeMapper = &localVolumeMapper{}
610610
var _ volume.CustomBlockVolumeMapper = &localVolumeMapper{}
611611

612612
// SetUpDevice prepares the volume to the node by the plugin specific way.
613-
func (m *localVolumeMapper) SetUpDevice() error {
614-
return nil
613+
func (m *localVolumeMapper) SetUpDevice() (string, error) {
614+
return "", nil
615615
}
616616

617617
// MapPodDevice provides physical device path for the local PV.

pkg/volume/util/operationexecutor/operation_generator.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
947947

948948
mapVolumeFunc := func() (simpleErr error, detailedErr error) {
949949
var devicePath string
950+
var stagingPath string
950951
// Set up global map path under the given plugin directory using symbolic link
951952
globalMapPath, err :=
952953
blockVolumeMapper.GetGlobalMapPath(volumeToMount.VolumeSpec)
@@ -970,7 +971,8 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
970971
}
971972
// Call SetUpDevice if blockVolumeMapper implements CustomBlockVolumeMapper
972973
if customBlockVolumeMapper, ok := blockVolumeMapper.(volume.CustomBlockVolumeMapper); ok {
973-
mapErr := customBlockVolumeMapper.SetUpDevice()
974+
var mapErr error
975+
stagingPath, mapErr = customBlockVolumeMapper.SetUpDevice()
974976
if mapErr != nil {
975977
og.markDeviceErrorState(volumeToMount, devicePath, globalMapPath, mapErr, actualStateOfWorld)
976978
// On failure, return error. Caller will log and retry.
@@ -1073,8 +1075,9 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
10731075
klog.V(verbosity).Infof(detailedMsg)
10741076

10751077
resizeOptions := volume.NodeResizeOptions{
1076-
DevicePath: devicePath,
1077-
CSIVolumePhase: volume.CSIVolumePublished,
1078+
DevicePath: devicePath,
1079+
DeviceStagePath: stagingPath,
1080+
CSIVolumePhase: volume.CSIVolumePublished,
10781081
}
10791082
_, resizeError := og.nodeExpandVolume(volumeToMount, resizeOptions)
10801083
if resizeError != nil {

pkg/volume/volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ type CustomBlockVolumeMapper interface {
174174
// For most in-tree plugins, attacher.Attach() and attacher.WaitForAttach()
175175
// will do necessary works.
176176
// This may be called more than once, so implementations must be idempotent.
177-
SetUpDevice() error
177+
SetUpDevice() (string, error)
178178

179179
// MapPodDevice maps the block device to a path and return the path.
180180
// Unique device path across kubelet node reboot is required to avoid

0 commit comments

Comments
 (0)