diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index b020bdef0..f0ac0a479 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -32,7 +32,6 @@ import ( "github.com/kubernetes-csi/csi-lib-utils/protosanitizer" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "google.golang.org/protobuf/types/known/timestamppb" ) const ( @@ -1236,14 +1235,13 @@ func (cs *ControllerServer) CreateSnapshot( return nil, status.Error(codes.Internal, err.Error()) } + csiSnap, err := vol.toSnapshot().ToCSI(ctx) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &csi.CreateSnapshotResponse{ - Snapshot: &csi.Snapshot{ - SizeBytes: vol.VolSize, - SnapshotId: vol.VolID, - SourceVolumeId: req.GetSourceVolumeId(), - CreationTime: timestamppb.New(*vol.CreatedAt), - ReadyToUse: true, - }, + Snapshot: csiSnap, }, nil } @@ -1296,14 +1294,13 @@ func cloneFromSnapshot( } } + csiSnap, err := rbdSnap.ToCSI(ctx) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &csi.CreateSnapshotResponse{ - Snapshot: &csi.Snapshot{ - SizeBytes: rbdSnap.VolSize, - SnapshotId: rbdSnap.VolID, - SourceVolumeId: rbdSnap.SourceVolumeID, - CreationTime: timestamppb.New(*rbdSnap.CreatedAt), - ReadyToUse: true, - }, + Snapshot: csiSnap, }, nil } diff --git a/internal/rbd/snapshot.go b/internal/rbd/snapshot.go index 15f1db5cb..fd7badb41 100644 --- a/internal/rbd/snapshot.go +++ b/internal/rbd/snapshot.go @@ -101,6 +101,27 @@ func cleanUpSnapshot( return nil } +func (rv *rbdVolume) toSnapshot() *rbdSnapshot { + return &rbdSnapshot{ + rbdImage: rbdImage{ + ClusterID: rv.ClusterID, + VolID: rv.VolID, + Monitors: rv.Monitors, + Pool: rv.Pool, + JournalPool: rv.JournalPool, + RadosNamespace: rv.RadosNamespace, + RbdImageName: rv.RbdImageName, + ImageID: rv.ImageID, + CreatedAt: rv.CreatedAt, + // copyEncryptionConfig cannot be used here because the volume and the + // snapshot will have the same volumeID which cases the panic in + // copyEncryptionConfig function. + blockEncryption: rv.blockEncryption, + fileEncryption: rv.fileEncryption, + }, + } +} + func (rbdSnap *rbdSnapshot) toVolume() *rbdVolume { return &rbdVolume{ rbdImage: rbdImage{ @@ -112,6 +133,7 @@ func (rbdSnap *rbdSnapshot) toVolume() *rbdVolume { RadosNamespace: rbdSnap.RadosNamespace, RbdImageName: rbdSnap.RbdSnapName, ImageID: rbdSnap.ImageID, + CreatedAt: rbdSnap.CreatedAt, // copyEncryptionConfig cannot be used here because the volume and the // snapshot will have the same volumeID which cases the panic in // copyEncryptionConfig function.