From f9ebe14e1687c08ef54f67539723072ae5211926 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Thu, 10 Sep 2026 17:10:08 +0800 Subject: [PATCH] add backup/restore type and fallback to backup/restore describe Signed-off-by: Lyndon-Li --- pkg/cmd/util/output/backup_describer.go | 13 ++++-- pkg/cmd/util/output/backup_describer_test.go | 38 ++++++++++++++++- .../output/backup_structured_describer.go | 12 ++++-- .../backup_structured_describer_test.go | 42 ++++++++++++++++++- pkg/cmd/util/output/restore_describer.go | 9 +++- pkg/cmd/util/output/restore_describer_test.go | 35 +++++++++++++++- .../output/restore_structured_describer.go | 9 +++- .../restore_structured_describer_test.go | 37 +++++++++++++++- 8 files changed, 179 insertions(+), 16 deletions(-) diff --git a/pkg/cmd/util/output/backup_describer.go b/pkg/cmd/util/output/backup_describer.go index 6c8d5860d..93ca28c7c 100644 --- a/pkg/cmd/util/output/backup_describer.go +++ b/pkg/cmd/util/output/backup_describer.go @@ -741,6 +741,16 @@ func describeDataMovement(d *Describer, details bool, info *volume.BackupVolumeI dataMover = info.SnapshotDataMovementInfo.DataMover } d.Printf("\t\t\t\tData Mover: %s\n", dataMover) + + if info.BackupType != "" { + backupType := string(info.BackupType) + if info.FallbackFull { + backupType += " (fallen back to Full)" + } + + d.Printf("\t\t\t\tBackup Type: %s\n", backupType) + } + d.Printf("\t\t\t\tUploader Type: %s\n", info.SnapshotDataMovementInfo.UploaderType) d.Printf("\t\t\t\tMoved data Size (bytes): %d\n", info.SnapshotDataMovementInfo.Size) // Print whenever the uploader measured a figure, including zero. A zero-delta @@ -750,9 +760,6 @@ func describeDataMovement(d *Describer, details bool, info *volume.BackupVolumeI if info.SnapshotDataMovementInfo.IncrementalSize != nil { d.Printf("\t\t\t\tIncremental data Size (bytes): %d\n", *info.SnapshotDataMovementInfo.IncrementalSize) } - if info.SnapshotDataMovementInfo.ParentSnapshot != "" { - d.Printf("\t\t\t\tParent Snapshot: %s\n", info.SnapshotDataMovementInfo.ParentSnapshot) - } d.Printf("\t\t\t\tResult: %s\n", info.Result) } else { diff --git a/pkg/cmd/util/output/backup_describer_test.go b/pkg/cmd/util/output/backup_describer_test.go index 4578d1301..bf312fbd3 100644 --- a/pkg/cmd/util/output/backup_describer_test.go +++ b/pkg/cmd/util/output/backup_describer_test.go @@ -635,7 +635,6 @@ func TestCSISnapshots(t *testing.T) { Size: 100, IncrementalSize: ptr.To(int64(50)), Phase: velerov2alpha1.DataUploadPhaseFailed, - ParentSnapshot: "fake-parent-snapshot", }, }, }, @@ -645,11 +644,46 @@ func TestCSISnapshots(t *testing.T) { Data Movement: Operation ID: fake-operation-5 Data Mover: velero + Backup Type: Incremental Uploader Type: fake-uploader Moved data Size (bytes): 100 Incremental data Size (bytes): 50 - Parent Snapshot: fake-parent-snapshot Result: failed +`, + }, + { + name: "details, data movement, incremental fallback to full", + volumeInfo: []*volume.BackupVolumeInfo{ + { + BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-6", + PVCName: "pvc-6", + Result: volume.VolumeResultSucceeded, + SnapshotDataMoved: true, + BackupType: velerov1api.BackupTypeIncremental, + FallbackFull: true, + SnapshotDataMovementInfo: &volume.BackupSnapshotDataMovementInfo{ + DataMover: "velero", + UploaderType: "fake-uploader", + SnapshotHandle: "fake-repo-id-6", + OperationID: "fake-operation-6", + Size: 200, + IncrementalSize: ptr.To(int64(200)), + Phase: velerov2alpha1.DataUploadPhaseCompleted, + }, + }, + }, + inputDetails: true, + expect: ` CSI Snapshots: + pvc-ns-6/pvc-6: + Data Movement: + Operation ID: fake-operation-6 + Data Mover: velero + Backup Type: Incremental (fallen back to Full) + Uploader Type: fake-uploader + Moved data Size (bytes): 200 + Incremental data Size (bytes): 200 + Result: succeeded `, }, } diff --git a/pkg/cmd/util/output/backup_structured_describer.go b/pkg/cmd/util/output/backup_structured_describer.go index d8fa66020..ef5ed4269 100644 --- a/pkg/cmd/util/output/backup_structured_describer.go +++ b/pkg/cmd/util/output/backup_structured_describer.go @@ -462,6 +462,15 @@ func describeDataMovementInSF(details bool, info *volume.BackupVolumeInfo, snaps dataMovement := make(map[string]any) dataMovement["operationID"] = info.SnapshotDataMovementInfo.OperationID + if info.BackupType != "" { + backupType := string(info.BackupType) + if info.FallbackFull { + backupType += " (fallen back to Full)" + } + + dataMovement["backupType"] = backupType + } + dataMover := "velero" if info.SnapshotDataMovementInfo.DataMover != "" { dataMover = info.SnapshotDataMovementInfo.DataMover @@ -478,9 +487,6 @@ func describeDataMovementInSF(details bool, info *volume.BackupVolumeInfo, snaps if info.SnapshotDataMovementInfo.IncrementalSize != nil { dataMovement["incrementalSize"] = *info.SnapshotDataMovementInfo.IncrementalSize } - if info.SnapshotDataMovementInfo.ParentSnapshot != "" { - dataMovement["parentSnapshot"] = info.SnapshotDataMovementInfo.ParentSnapshot - } snapshotDetail["dataMovement"] = dataMovement } else { diff --git a/pkg/cmd/util/output/backup_structured_describer_test.go b/pkg/cmd/util/output/backup_structured_describer_test.go index f7065590b..c639aff58 100644 --- a/pkg/cmd/util/output/backup_structured_describer_test.go +++ b/pkg/cmd/util/output/backup_structured_describer_test.go @@ -585,7 +585,6 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { Size: 100, IncrementalSize: ptr.To(int64(50)), Phase: velerov2alpha1.DataUploadPhaseFailed, - ParentSnapshot: "fake-parent-snapshot", }, }, }, @@ -596,11 +595,50 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { "dataMovement": map[string]any{ "operationID": "fake-operation-4", "dataMover": "velero", + "backupType": "Incremental", "uploaderType": "fake-uploader", "size": int64(100), "incrementalSize": int64(50), "result": "failed", - "parentSnapshot": "fake-parent-snapshot", + }, + }, + }, + }, + }, + { + name: "details, data movement, incremental fallback to full", + volumeInfo: []*volume.BackupVolumeInfo{ + { + BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-5", + Result: volume.VolumeResultSucceeded, + PVCName: "pvc-5", + SnapshotDataMoved: true, + BackupType: velerov1api.BackupTypeIncremental, + FallbackFull: true, + SnapshotDataMovementInfo: &volume.BackupSnapshotDataMovementInfo{ + DataMover: "velero", + UploaderType: "fake-uploader", + SnapshotHandle: "fake-repo-id-5", + OperationID: "fake-operation-5", + Size: 200, + IncrementalSize: ptr.To(int64(200)), + Phase: velerov2alpha1.DataUploadPhaseCompleted, + }, + }, + }, + inputDetails: true, + expect: map[string]any{ + "csiSnapshots": map[string]any{ + "pvc-ns-5/pvc-5": map[string]any{ + "dataMovement": map[string]any{ + "operationID": "fake-operation-5", + "dataMover": "velero", + "backupType": "Incremental (fallen back to Full)", + "uploaderType": "fake-uploader", + "size": int64(200), + "incrementalSize": int64(200), + "result": "succeeded", }, }, }, diff --git a/pkg/cmd/util/output/restore_describer.go b/pkg/cmd/util/output/restore_describer.go index b5c2dba45..0258a7fc0 100644 --- a/pkg/cmd/util/output/restore_describer.go +++ b/pkg/cmd/util/output/restore_describer.go @@ -473,8 +473,13 @@ func describeCSISnapshotsRestores(d *Describer, restoreVolInfo []volume.RestoreV d.Printf("\t\t\tOperation ID: %s\n", info.SnapshotDataMovementInfo.OperationID) d.Printf("\t\t\tData Mover: %s\n", info.SnapshotDataMovementInfo.DataMover) d.Printf("\t\t\tUploader Type: %s\n", info.SnapshotDataMovementInfo.UploaderType) - if info.SnapshotDataMovementInfo.RestoreType != "" { - d.Printf("\t\t\tRestore Type: %s\n", info.SnapshotDataMovementInfo.RestoreType) + if info.RestoreType != "" { + restoreType := info.RestoreType + if info.FallbackFull { + restoreType += " (fallen back to Full)" + } + + d.Printf("\t\t\tRestore Type: %s\n", restoreType) } if info.SnapshotDataMovementInfo.Size > 0 { d.Printf("\t\t\tRestored data Size (bytes): %d\n", info.SnapshotDataMovementInfo.Size) diff --git a/pkg/cmd/util/output/restore_describer_test.go b/pkg/cmd/util/output/restore_describer_test.go index cb2827315..d74a8b53b 100644 --- a/pkg/cmd/util/output/restore_describer_test.go +++ b/pkg/cmd/util/output/restore_describer_test.go @@ -312,13 +312,13 @@ CSI Snapshot Restores: PVName: "pv-3", RestoreMethod: volume.CSISnapshot, SnapshotDataMoved: true, + RestoreType: "Incremental", SnapshotDataMovementInfo: &volume.RestoreSnapshotDataMovementInfo{ OperationID: "op-3", DataMover: "velero", UploaderType: "kopia", Size: 1234, IncrementalSize: ptr.To(int64(500)), - RestoreType: "Incremental", }, }, }, @@ -333,6 +333,39 @@ CSI Snapshot Restores: Restore Type: Incremental Restored data Size (bytes): 1234 Incremental data Size (bytes): 500 +`, + }, + { + name: "CSI restore with data movement, detailed, fallback to full", + inputVolInfoList: []volume.RestoreVolumeInfo{ + { + PVCName: "pvc-4", + PVCNamespace: "ns-4", + PVName: "pv-4", + RestoreMethod: volume.CSISnapshot, + SnapshotDataMoved: true, + RestoreType: "Incremental", + FallbackFull: true, + SnapshotDataMovementInfo: &volume.RestoreSnapshotDataMovementInfo{ + OperationID: "op-4", + DataMover: "velero", + UploaderType: "kopia", + Size: 2345, + IncrementalSize: ptr.To(int64(600)), + }, + }, + }, + inputDetail: true, + expect: ` +CSI Snapshot Restores: + ns-4/pvc-4: + Data Movement: + Operation ID: op-4 + Data Mover: velero + Uploader Type: kopia + Restore Type: Incremental (fallen back to Full) + Restored data Size (bytes): 2345 + Incremental data Size (bytes): 600 `, }, { diff --git a/pkg/cmd/util/output/restore_structured_describer.go b/pkg/cmd/util/output/restore_structured_describer.go index 31a71b68c..d5b4cd075 100644 --- a/pkg/cmd/util/output/restore_structured_describer.go +++ b/pkg/cmd/util/output/restore_structured_describer.go @@ -372,8 +372,13 @@ func describeCSISnapshotsRestoresInSF(d *StructuredDescriber, restoreVolInfo []v "dataMover": info.SnapshotDataMovementInfo.DataMover, "uploaderType": info.SnapshotDataMovementInfo.UploaderType, } - if info.SnapshotDataMovementInfo.RestoreType != "" { - dmInfo["restoreType"] = info.SnapshotDataMovementInfo.RestoreType + if info.RestoreType != "" { + restoreType := info.RestoreType + if info.FallbackFull { + restoreType += " (fallen back to Full)" + } + + dmInfo["restoreType"] = restoreType } if info.SnapshotDataMovementInfo.Size > 0 { dmInfo["size"] = info.SnapshotDataMovementInfo.Size diff --git a/pkg/cmd/util/output/restore_structured_describer_test.go b/pkg/cmd/util/output/restore_structured_describer_test.go index c6b1de2b7..22b6499b6 100644 --- a/pkg/cmd/util/output/restore_structured_describer_test.go +++ b/pkg/cmd/util/output/restore_structured_describer_test.go @@ -473,13 +473,13 @@ func TestDescribeRestoreCSISnapshotsInSF_NoData(t *testing.T) { SnapshotDataMoved: true, PVCName: "pvc-3", PVCNamespace: "ns-3", + RestoreType: "Incremental", SnapshotDataMovementInfo: &volume.RestoreSnapshotDataMovementInfo{ OperationID: "op-3", DataMover: "velero", UploaderType: "kopia", Size: 1234, IncrementalSize: ptr.To(int64(500)), - RestoreType: "Incremental", }, }, }, @@ -499,6 +499,41 @@ func TestDescribeRestoreCSISnapshotsInSF_NoData(t *testing.T) { }, }, }, + { + name: "data movement entry, with details, fallback to full", + inputVolInfoList: []volume.RestoreVolumeInfo{ + { + RestoreMethod: volume.CSISnapshot, + SnapshotDataMoved: true, + PVCName: "pvc-4", + PVCNamespace: "ns-4", + RestoreType: "Incremental", + FallbackFull: true, + SnapshotDataMovementInfo: &volume.RestoreSnapshotDataMovementInfo{ + OperationID: "op-4", + DataMover: "velero", + UploaderType: "kopia", + Size: 2345, + IncrementalSize: ptr.To(int64(600)), + }, + }, + }, + details: true, + expect: map[string]any{ + "csiSnapshotRestores": map[string]any{ + "ns-4/pvc-4": map[string]any{ + "dataMovement": map[string]any{ + "operationID": "op-4", + "dataMover": "velero", + "uploaderType": "kopia", + "size": int64(2345), + "incrementalSize": int64(600), + "restoreType": "Incremental (fallen back to Full)", + }, + }, + }, + }, + }, { name: "data movement entry, no details", inputVolInfoList: []volume.RestoreVolumeInfo{