From 148210530962c11428806f28da7996c802e86f07 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 8 Apr 2021 13:24:38 +0200 Subject: [PATCH] cleanup: use buildCreateVolumeResponse() to simplify CreateVolume() buildCreateVolumeResponse() exists exactly for the need to create a csi.CreateVolumeResponse based on an rbdVolume. Calling this helper reduces the code duplication in CreateVolume(). Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 87d3f04ca..d2af31294 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -218,7 +218,6 @@ func validateRequestedVolumeSize(rbdVol, parentVol *rbdVolume, rbdSnap *rbdSnaps } // CreateVolume creates the volume in backend. -// nolint:gocyclo // encrypted cloning/snapshots added more complexity, this needs to be addressed func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { if err := cs.validateVolumeReq(ctx, req); err != nil { return nil, err @@ -305,26 +304,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol return nil, err } - volumeContext := req.GetParameters() - volumeContext["pool"] = rbdVol.Pool - volumeContext["journalPool"] = rbdVol.JournalPool - volumeContext["radosNamespace"] = rbdVol.RadosNamespace - volumeContext["imageName"] = rbdVol.RbdImageName - volume := &csi.Volume{ - VolumeId: rbdVol.VolID, - CapacityBytes: rbdVol.VolSize, - VolumeContext: volumeContext, - ContentSource: req.GetVolumeContentSource(), - } - if rbdVol.Topology != nil { - volume.AccessibleTopology = - []*csi.Topology{ - { - Segments: rbdVol.Topology, - }, - } - } - return &csi.CreateVolumeResponse{Volume: volume}, nil + return buildCreateVolumeResponse(req, rbdVol), nil } func flattenParentImage(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {