mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
rbd: check volume details from original volumeID
Checking volume details for the existing volumeID first. if details like OMAP, RBD Image, Pool doesnot exists try to use clusterIDMapping to look for the correct informations. fixes: #2929 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
6bba64c872
commit
07e9dede2c
@ -25,7 +25,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
|
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
|
||||||
"github.com/ceph/ceph-csi/internal/journal"
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
"github.com/ceph/ceph-csi/internal/util/fscrypt"
|
"github.com/ceph/ceph-csi/internal/util/fscrypt"
|
||||||
"github.com/ceph/ceph-csi/internal/util/log"
|
"github.com/ceph/ceph-csi/internal/util/log"
|
||||||
@ -144,14 +143,12 @@ func healerStageTransaction(ctx context.Context, cr *util.Credentials, volOps *r
|
|||||||
// this function also receive the credentials and secrets args as it differs in its data.
|
// this function also receive the credentials and secrets args as it differs in its data.
|
||||||
// The credentials are used directly by functions like voljournal.Connect() and other functions
|
// The credentials are used directly by functions like voljournal.Connect() and other functions
|
||||||
// like genVolFromVolumeOptions() make use of secrets.
|
// like genVolFromVolumeOptions() make use of secrets.
|
||||||
// nolint:gocyclo,cyclop // reduce complexity
|
|
||||||
func populateRbdVol(
|
func populateRbdVol(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *csi.NodeStageVolumeRequest,
|
req *csi.NodeStageVolumeRequest,
|
||||||
cr *util.Credentials,
|
cr *util.Credentials,
|
||||||
) (*rbdVolume, error) {
|
) (*rbdVolume, error) {
|
||||||
var err error
|
var err error
|
||||||
var j *journal.Connection
|
|
||||||
volID := req.GetVolumeId()
|
volID := req.GetVolumeId()
|
||||||
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
||||||
disableInUseChecks := false
|
disableInUseChecks := false
|
||||||
@ -173,11 +170,7 @@ func populateRbdVol(
|
|||||||
|
|
||||||
disableInUseChecks = true
|
disableInUseChecks = true
|
||||||
}
|
}
|
||||||
|
var rv *rbdVolume
|
||||||
rv, err := genVolFromVolumeOptions(ctx, req.GetVolumeContext(), disableInUseChecks, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
isStaticVol := parseBoolOption(ctx, req.GetVolumeContext(), staticVol, false)
|
isStaticVol := parseBoolOption(ctx, req.GetVolumeContext(), staticVol, false)
|
||||||
// get rbd image name from the volume journal
|
// get rbd image name from the volume journal
|
||||||
@ -187,35 +180,24 @@ func populateRbdVol(
|
|||||||
// if migration static volume, use imageName as volID
|
// if migration static volume, use imageName as volID
|
||||||
volID = req.GetVolumeContext()["imageName"]
|
volID = req.GetVolumeContext()["imageName"]
|
||||||
}
|
}
|
||||||
|
rv, err = genVolFromVolumeOptions(ctx, req.GetVolumeContext(), disableInUseChecks, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
rv.RbdImageName = volID
|
rv.RbdImageName = volID
|
||||||
} else {
|
} else {
|
||||||
var vi util.CSIIdentifier
|
rv, err = GenVolFromVolID(ctx, volID, cr, req.GetSecrets())
|
||||||
var imageAttributes *journal.ImageAttributes
|
|
||||||
err = vi.DecomposeCSIID(volID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("error decoding volume ID (%s): %w", volID, err)
|
rv.Destroy()
|
||||||
|
log.ErrorLog(ctx, "error generating volume %s: %v", volID, err)
|
||||||
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Errorf(codes.Internal, "error generating volume %s: %v", volID, err)
|
||||||
}
|
}
|
||||||
|
rv.DataPool = req.GetVolumeContext()["dataPool"]
|
||||||
j, err = volJournal.Connect(rv.Monitors, rv.RadosNamespace, cr)
|
var ok bool
|
||||||
if err != nil {
|
if rv.Mounter, ok = req.GetVolumeContext()["mounter"]; !ok {
|
||||||
log.ErrorLog(ctx, "failed to establish cluster connection: %v", err)
|
rv.Mounter = rbdDefaultMounter
|
||||||
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
|
||||||
}
|
}
|
||||||
defer j.Destroy()
|
|
||||||
|
|
||||||
imageAttributes, err = j.GetImageAttributes(
|
|
||||||
ctx, rv.Pool, vi.ObjectUUID, false)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("error fetching image attributes for volume ID (%s): %w", volID, err)
|
|
||||||
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
|
||||||
}
|
|
||||||
rv.RbdImageName = imageAttributes.ImageName
|
|
||||||
// set owner after extracting the owner name from the journal
|
|
||||||
rv.Owner = imageAttributes.Owner
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = rv.Connect(cr)
|
err = rv.Connect(cr)
|
||||||
|
Loading…
Reference in New Issue
Block a user