Fix updating restore size issue
This PR fixed the issue of not updating the snapshot restore size after snapshot is created. Before snapshot is ready, the returned size might not be accurate. So we need to keep updating the snapshot size during checking the snapshot status.
This commit is contained in:
@@ -51,8 +51,8 @@ type CSIConnection interface {
|
||||
// DeleteSnapshot deletes a snapshot from a volume
|
||||
DeleteSnapshot(ctx context.Context, snapshotID string, snapshotterCredentials map[string]string) (err error)
|
||||
|
||||
// GetSnapshotStatus lists snapshot from a volume
|
||||
GetSnapshotStatus(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, error)
|
||||
// GetSnapshotStatus returns a snapshot's status, creation time, and restore size.
|
||||
GetSnapshotStatus(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, int64, error)
|
||||
|
||||
// Probe checks that the CSI driver is ready to process requests
|
||||
Probe(ctx context.Context) error
|
||||
@@ -232,7 +232,7 @@ func (c *csiConnection) DeleteSnapshot(ctx context.Context, snapshotID string, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, error) {
|
||||
func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, int64, error) {
|
||||
client := csi.NewControllerClient(c.conn)
|
||||
|
||||
req := csi.ListSnapshotsRequest{
|
||||
@@ -241,14 +241,14 @@ func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string
|
||||
|
||||
rsp, err := client.ListSnapshots(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
if rsp.Entries == nil || len(rsp.Entries) == 0 {
|
||||
return nil, 0, fmt.Errorf("can not find snapshot for snapshotID %s", snapshotID)
|
||||
return nil, 0, 0, fmt.Errorf("can not find snapshot for snapshotID %s", snapshotID)
|
||||
}
|
||||
|
||||
return rsp.Entries[0].Snapshot.Status, rsp.Entries[0].Snapshot.CreatedAt, nil
|
||||
return rsp.Entries[0].Snapshot.Status, rsp.Entries[0].Snapshot.CreatedAt, rsp.Entries[0].Snapshot.SizeBytes, nil
|
||||
}
|
||||
|
||||
func (c *csiConnection) Close() error {
|
||||
|
@@ -658,6 +658,7 @@ func TestDeleteSnapshot(t *testing.T) {
|
||||
func TestGetSnapshotStatus(t *testing.T) {
|
||||
defaultID := "testid"
|
||||
createdAt := time.Now().UnixNano()
|
||||
size := int64(1000)
|
||||
|
||||
defaultRequest := &csi.ListSnapshotsRequest{
|
||||
SnapshotId: defaultID,
|
||||
@@ -668,7 +669,7 @@ func TestGetSnapshotStatus(t *testing.T) {
|
||||
{
|
||||
Snapshot: &csi.Snapshot{
|
||||
Id: defaultID,
|
||||
SizeBytes: 1000,
|
||||
SizeBytes: size,
|
||||
SourceVolumeId: "volumeid",
|
||||
CreatedAt: createdAt,
|
||||
Status: &csi.SnapshotStatus{
|
||||
@@ -689,6 +690,7 @@ func TestGetSnapshotStatus(t *testing.T) {
|
||||
expectError bool
|
||||
expectStatus *csi.SnapshotStatus
|
||||
expectCreateAt int64
|
||||
expectSize int64
|
||||
}{
|
||||
{
|
||||
name: "success",
|
||||
@@ -701,6 +703,7 @@ func TestGetSnapshotStatus(t *testing.T) {
|
||||
Details: "success",
|
||||
},
|
||||
expectCreateAt: createdAt,
|
||||
expectSize: size,
|
||||
},
|
||||
{
|
||||
name: "gRPC transient error",
|
||||
@@ -741,7 +744,7 @@ func TestGetSnapshotStatus(t *testing.T) {
|
||||
controllerServer.EXPECT().ListSnapshots(gomock.Any(), in).Return(out, injectedErr).Times(1)
|
||||
}
|
||||
|
||||
status, createTime, err := csiConn.GetSnapshotStatus(context.Background(), test.snapshotID)
|
||||
status, createTime, size, err := csiConn.GetSnapshotStatus(context.Background(), test.snapshotID)
|
||||
if test.expectError && err == nil {
|
||||
t.Errorf("test %q: Expected error, got none", test.name)
|
||||
}
|
||||
@@ -754,6 +757,9 @@ func TestGetSnapshotStatus(t *testing.T) {
|
||||
if test.expectCreateAt != createTime {
|
||||
t.Errorf("test %q: expected createTime: %v, got: %v", test.name, test.expectCreateAt, createTime)
|
||||
}
|
||||
if test.expectSize != size {
|
||||
t.Errorf("test %q: expected size: %v, got: %v", test.name, test.expectSize, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user