mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Supply staging path for block expansion
This commit is contained in:
parent
7d6959ce2c
commit
75e13e370e
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user