Skip to content

Commit

Permalink
rbd: add migration secret support to controllerserver functions
Browse files Browse the repository at this point in the history
This commit adds the migration secret request validation to expand,
create controller functions.

Ref # ceph#2509

Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec committed Nov 22, 2021
1 parent 929e17d commit 3cb75d1
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (cs *ControllerServer) validateVolumeReq(ctx context.Context, req *csi.Crea

func (cs *ControllerServer) parseVolCreateRequest(
ctx context.Context,
req *csi.CreateVolumeRequest) (*rbdVolume, error) {
req *csi.CreateVolumeRequest, secrets map[string]string) (*rbdVolume, error) {
// TODO (sbezverk) Last check for not exceeding total storage capacity

isMultiNode := false
Expand Down Expand Up @@ -125,7 +125,7 @@ func (cs *ControllerServer) parseVolCreateRequest(
// if it's NOT SINGLE_NODE_WRITER and it's BLOCK we'll set the parameter to ignore the in-use checks
rbdVol, err := genVolFromVolumeOptions(
ctx,
req.GetParameters(), req.GetSecrets(),
req.GetParameters(), secrets,
(isMultiNode && isBlock), false)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
Expand Down Expand Up @@ -271,19 +271,27 @@ func checkValidCreateVolumeRequest(rbdVol, parentVol *rbdVolume, rbdSnap *rbdSna
func (cs *ControllerServer) CreateVolume(
ctx context.Context,
req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
if err := cs.validateVolumeReq(ctx, req); err != nil {
var err error
if err = cs.validateVolumeReq(ctx, req); err != nil {
return nil, err
}

// TODO: create/get a connection from the the ConnPool, and do not pass
// the credentials to any of the utility functions.
cr, err := util.NewUserCredentials(req.GetSecrets())
secrets := req.GetSecrets()
if util.IsMigrationSecret(secrets) {
secrets, err = util.ParseAndSetSecretMapFromMigSecret(secrets)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
}
cr, err := util.NewUserCredentials(secrets)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
defer cr.DeleteCredentials()

rbdVol, err := cs.parseVolCreateRequest(ctx, req)
rbdVol, err := cs.parseVolCreateRequest(ctx, req, secrets)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1432,7 +1440,8 @@ func (cs *ControllerServer) DeleteSnapshot(
func (cs *ControllerServer) ControllerExpandVolume(
ctx context.Context,
req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME); err != nil {
var err error
if err = cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME); err != nil {
log.ErrorLog(ctx, "invalid expand volume req: %v", protosanitizer.StripSecrets(req))

return nil, err
Expand All @@ -1456,13 +1465,21 @@ func (cs *ControllerServer) ControllerExpandVolume(
}
defer cs.VolumeLocks.Release(volID)

cr, err := util.NewUserCredentials(req.GetSecrets())
secrets := req.GetSecrets()
if util.IsMigrationSecret(secrets) {
secrets, err = util.ParseAndSetSecretMapFromMigSecret(secrets)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
}

cr, err := util.NewUserCredentials(secrets)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
defer cr.DeleteCredentials()

rbdVol, err := genVolFromVolID(ctx, volID, cr, req.GetSecrets())
rbdVol, err := genVolFromVolID(ctx, volID, cr, secrets)
defer rbdVol.Destroy()
if err != nil {
switch {
Expand Down

0 comments on commit 3cb75d1

Please sign in to comment.