Skip to content

Commit

Permalink
Merge pull request #590 from mowangdk/add_snapshot_size
Browse files Browse the repository at this point in the history
Add source pvc disk size to snapshot restore size
  • Loading branch information
fredkan committed Jan 21, 2022
2 parents 9992a23 + a02a90d commit e84838c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
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
}

0 comments on commit e84838c

Please sign in to comment.