Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source pvc disk size to snapshot restore size #590

Merged
merged 1 commit into from Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/disk/controllerserver.go
Expand Up @@ -698,6 +698,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
// used for snapshot events
snapshotName := req.Parameters[VolumeSnapshotName]
snapshotNamespace := req.Parameters[VolumeSnapshotNamespace]

ref := &v1.ObjectReference{
Kind: "VolumeSnapshot",
Name: snapshotName,
Expand Down Expand Up @@ -846,6 +847,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
SourceVolumeId: sourceVolumeID,
CreationTime: createAt,
ReadyToUse: tmpReadyToUse,
SizeBytes: gi2Bytes(int64(disks[0].Size)),
}

createdSnapshotMap[req.Name] = csiSnapshot
Expand Down Expand Up @@ -1181,7 +1183,7 @@ func formatCSISnapshot(ecsSnapshot *ecs.Snapshot) (*csi.Snapshot, error) {
return nil, status.Errorf(codes.Internal, "failed to parse snapshot creation time: %s", ecsSnapshot.CreationTime)
}
sizeGb, _ := strconv.ParseInt(ecsSnapshot.SourceDiskSize, 10, 64)
sizeBytes := sizeGb * 1024 * 1024 * 1024
sizeBytes := gi2Bytes(sizeGb)
readyToUse := false
if ecsSnapshot.Status == "accomplished" || ecsSnapshot.InstantAccess {
readyToUse = true
Expand All @@ -1194,3 +1196,7 @@ func formatCSISnapshot(ecsSnapshot *ecs.Snapshot) (*csi.Snapshot, error) {
ReadyToUse: readyToUse,
}, nil
}

func gi2Bytes(gb int64) int64 {
return gb * 1024 * 1024 * 1024
}