rbd: do not pass Credentials to checkVolExists()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-03-17 13:57:01 +01:00 committed by mergify[bot]
parent 805f10fd71
commit 12130123ac
2 changed files with 12 additions and 6 deletions

View File

@ -156,7 +156,13 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
} }
defer cs.VolumeLocks.Release(req.GetName()) defer cs.VolumeLocks.Release(req.GetName())
found, err := checkVolExists(ctx, rbdVol, cr) err = rbdVol.Connect(cr)
if err != nil {
klog.Errorf(util.Log(ctx, "failed to connect to volume %v: %v"), rbdVol.RbdImageName, err)
return nil, status.Error(codes.Internal, err.Error())
}
found, err := rbdVol.Exists(ctx)
if err != nil { if err != nil {
if _, ok := err.(ErrVolNameConflict); ok { if _, ok := err.(ErrVolNameConflict); ok {
return nil, status.Error(codes.AlreadyExists, err.Error()) return nil, status.Error(codes.AlreadyExists, err.Error())

View File

@ -163,7 +163,7 @@ volume names as requested by the CSI drivers. Hence, these need to be invoked on
respective CSI snapshot or volume name based locks are held, as otherwise racy access to these respective CSI snapshot or volume name based locks are held, as otherwise racy access to these
omaps may end up leaving the omaps in an inconsistent state. omaps may end up leaving the omaps in an inconsistent state.
*/ */
func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) (bool, error) { func (rbdVol *rbdVolume) Exists(ctx context.Context) (bool, error) {
err := validateRbdVol(rbdVol) err := validateRbdVol(rbdVol)
if err != nil { if err != nil {
return false, err return false, err
@ -174,7 +174,7 @@ func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials
kmsID = rbdVol.KMS.GetID() kmsID = rbdVol.KMS.GetID()
} }
imageData, err := volJournal.CheckReservation(ctx, rbdVol.Monitors, cr, rbdVol.JournalPool, imageData, err := volJournal.CheckReservation(ctx, rbdVol.Monitors, rbdVol.conn.Creds, rbdVol.JournalPool,
rbdVol.RequestName, rbdVol.NamePrefix, "", kmsID) rbdVol.RequestName, rbdVol.NamePrefix, "", kmsID)
if err != nil { if err != nil {
return false, err return false, err
@ -202,10 +202,10 @@ func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials
// save it for size checks before fetching image data // save it for size checks before fetching image data
requestSize := rbdVol.VolSize requestSize := rbdVol.VolSize
// Fetch on-disk image attributes and compare against request // Fetch on-disk image attributes and compare against request
err = updateVolWithImageInfo(ctx, rbdVol, cr) err = updateVolWithImageInfo(ctx, rbdVol, rbdVol.conn.Creds)
if err != nil { if err != nil {
if _, ok := err.(ErrImageNotFound); ok { if _, ok := err.(ErrImageNotFound); ok {
err = volJournal.UndoReservation(ctx, rbdVol.Monitors, cr, rbdVol.JournalPool, rbdVol.Pool, err = volJournal.UndoReservation(ctx, rbdVol.Monitors, rbdVol.conn.Creds, rbdVol.JournalPool, rbdVol.Pool,
rbdVol.RbdImageName, rbdVol.RequestName) rbdVol.RbdImageName, rbdVol.RequestName)
return false, err return false, err
} }
@ -221,7 +221,7 @@ func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials
// TODO: We should also ensure image features and format is the same // TODO: We should also ensure image features and format is the same
// found a volume already available, process and return it! // found a volume already available, process and return it!
rbdVol.VolID, err = util.GenerateVolID(ctx, rbdVol.Monitors, cr, imageData.ImagePoolID, rbdVol.Pool, rbdVol.VolID, err = util.GenerateVolID(ctx, rbdVol.Monitors, rbdVol.conn.Creds, imageData.ImagePoolID, rbdVol.Pool,
rbdVol.ClusterID, imageUUID, volIDVersion) rbdVol.ClusterID, imageUUID, volIDVersion)
if err != nil { if err != nil {
return false, err return false, err