From 2458ec65734a68a6d07ed10c8786d89bdf139bf8 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 30 Jul 2020 14:24:15 +0530 Subject: [PATCH] rbd: return error if fetching cluster id fails if we are not able to fetch the cluster-ID from the createSnapshot request and also if we are not able to get the monitor information from the cluster-ID return error instead of using the parent image information. Signed-off-by: Madhu Rajanna --- internal/rbd/controllerserver.go | 5 ++++- internal/rbd/rbd_util.go | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 9963f8c0b..bf051b266 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -726,7 +726,10 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS return nil, status.Errorf(codes.InvalidArgument, "volume(%s) has not snapshot feature(layering)", req.GetSourceVolumeId()) } - rbdSnap := genSnapFromOptions(ctx, rbdVol, req.GetParameters()) + rbdSnap, err := genSnapFromOptions(ctx, rbdVol, req.GetParameters()) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } rbdSnap.RbdImageName = rbdVol.RbdImageName rbdSnap.SizeBytes = rbdVol.VolSize rbdSnap.SourceVolumeID = req.GetSourceVolumeId() diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index b1932bb8c..f4ccb7d53 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -750,7 +750,7 @@ func genVolFromVolumeOptions(ctx context.Context, volOptions, credentials map[st return rbdVol, nil } -func genSnapFromOptions(ctx context.Context, rbdVol *rbdVolume, snapOptions map[string]string) *rbdSnapshot { +func genSnapFromOptions(ctx context.Context, rbdVol *rbdVolume, snapOptions map[string]string) (*rbdSnapshot, error) { var err error rbdSnap := &rbdSnapshot{} @@ -759,15 +759,14 @@ func genSnapFromOptions(ctx context.Context, rbdVol *rbdVolume, snapOptions map[ rbdSnap.Monitors, rbdSnap.ClusterID, err = getMonsAndClusterID(ctx, snapOptions) if err != nil { - rbdSnap.Monitors = rbdVol.Monitors - rbdSnap.ClusterID = rbdVol.ClusterID + return nil, err } if namePrefix, ok := snapOptions["snapshotNamePrefix"]; ok { rbdSnap.NamePrefix = namePrefix } - return rbdSnap + return rbdSnap, nil } // hasSnapshotFeature checks if Layering is enabled for this image.