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.