From 210838267fe3cc83b940b22088338fcb3b40e437 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Thu, 21 Dec 2023 10:02:27 +0800 Subject: [PATCH] issue 7237: add pvc namespace to backup describe Signed-off-by: Lyndon-Li --- pkg/cmd/util/output/backup_describer.go | 3 ++- pkg/cmd/util/output/backup_describer_test.go | 15 ++++++++++----- .../util/output/backup_structured_describer.go | 2 +- .../output/backup_structured_describer_test.go | 15 ++++++++++----- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/util/output/backup_describer.go b/pkg/cmd/util/output/backup_describer.go index 032c5bd53..8ae2df01a 100644 --- a/pkg/cmd/util/output/backup_describer.go +++ b/pkg/cmd/util/output/backup_describer.go @@ -585,6 +585,7 @@ func retrieveCSISnapshotLegacy(ctx context.Context, kbClient kbclient.Client, ba if *vs.Status.BoundVolumeSnapshotContentName == vsc.Name { volInfo.PVCName = *vs.Spec.Source.PersistentVolumeClaimName + volInfo.PVCNamespace = vs.Namespace } } @@ -639,7 +640,7 @@ func describeCSISnapshots(d *Describer, details bool, infos []*volume.VolumeInfo } func describeCSISnapshot(d *Describer, details bool, info *volume.VolumeInfo) { - d.Printf("\t\t%s:\n", info.PVCName) + d.Printf("\t\t%s:\n", fmt.Sprintf("%s/%s", info.PVCNamespace, info.PVCName)) describeLocalSnapshot(d, details, info) describeDataMovement(d, details, info) diff --git a/pkg/cmd/util/output/backup_describer_test.go b/pkg/cmd/util/output/backup_describer_test.go index 53aeed68f..b2b5ae074 100644 --- a/pkg/cmd/util/output/backup_describer_test.go +++ b/pkg/cmd/util/output/backup_describer_test.go @@ -397,6 +397,7 @@ func TestCSISnapshots(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-1", PVCName: "pvc-1", PreserveLocalSnapshot: true, OperationID: "fake-operation-1", @@ -409,7 +410,7 @@ func TestCSISnapshots(t *testing.T) { }, }, expect: ` CSI Snapshots: - pvc-1: + pvc-ns-1/pvc-1: Snapshot: included, specify --details for more information `, }, @@ -418,6 +419,7 @@ func TestCSISnapshots(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-2", PVCName: "pvc-2", PreserveLocalSnapshot: true, OperationID: "fake-operation-2", @@ -431,7 +433,7 @@ func TestCSISnapshots(t *testing.T) { }, inputDetails: true, expect: ` CSI Snapshots: - pvc-2: + pvc-ns-2/pvc-2: Snapshot: Operation ID: fake-operation-2 Snapshot Content Name: vsc-2 @@ -445,6 +447,7 @@ func TestCSISnapshots(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-3", PVCName: "pvc-3", SnapshotDataMoved: true, OperationID: "fake-operation-3", @@ -456,7 +459,7 @@ func TestCSISnapshots(t *testing.T) { }, }, expect: ` CSI Snapshots: - pvc-3: + pvc-ns-3/pvc-3: Data Movement: included, specify --details for more information `, }, @@ -465,6 +468,7 @@ func TestCSISnapshots(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-4", PVCName: "pvc-4", SnapshotDataMoved: true, OperationID: "fake-operation-4", @@ -477,7 +481,7 @@ func TestCSISnapshots(t *testing.T) { }, inputDetails: true, expect: ` CSI Snapshots: - pvc-4: + pvc-ns-4/pvc-4: Data Movement: Operation ID: fake-operation-4 Data Mover: velero @@ -489,6 +493,7 @@ func TestCSISnapshots(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-5", PVCName: "pvc-5", SnapshotDataMoved: true, OperationID: "fake-operation-5", @@ -500,7 +505,7 @@ func TestCSISnapshots(t *testing.T) { }, inputDetails: true, expect: ` CSI Snapshots: - pvc-5: + pvc-ns-5/pvc-5: Data Movement: Operation ID: fake-operation-5 Data Mover: velero diff --git a/pkg/cmd/util/output/backup_structured_describer.go b/pkg/cmd/util/output/backup_structured_describer.go index 17f0d0d35..23d19262a 100644 --- a/pkg/cmd/util/output/backup_structured_describer.go +++ b/pkg/cmd/util/output/backup_structured_describer.go @@ -407,7 +407,7 @@ func describeCSISnapshotInSF(details bool, info *volume.VolumeInfo, snapshotDeta describeLocalSnapshotInSF(details, info, snapshotDetail) describeDataMovementInSF(details, info, snapshotDetail) - snapshotDetails[info.PVCName] = snapshotDetail + snapshotDetails[fmt.Sprintf("%s/%s", info.PVCNamespace, info.PVCName)] = snapshotDetail } // describeVSCInSF describes CSI volume snapshot contents in structured format. diff --git a/pkg/cmd/util/output/backup_structured_describer_test.go b/pkg/cmd/util/output/backup_structured_describer_test.go index 2f65934f7..c19cfc2c0 100644 --- a/pkg/cmd/util/output/backup_structured_describer_test.go +++ b/pkg/cmd/util/output/backup_structured_describer_test.go @@ -357,6 +357,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-1", PVCName: "pvc-1", PreserveLocalSnapshot: true, OperationID: "fake-operation-1", @@ -370,7 +371,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, expect: map[string]interface{}{ "csiSnapshots": map[string]interface{}{ - "pvc-1": map[string]interface{}{ + "pvc-ns-1/pvc-1": map[string]interface{}{ "snapshot": "included, specify --details for more information", }, }, @@ -381,6 +382,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-2", PVCName: "pvc-2", PreserveLocalSnapshot: true, OperationID: "fake-operation-2", @@ -395,7 +397,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { inputDetails: true, expect: map[string]interface{}{ "csiSnapshots": map[string]interface{}{ - "pvc-2": map[string]interface{}{ + "pvc-ns-2/pvc-2": map[string]interface{}{ "snapshot": map[string]interface{}{ "operationID": "fake-operation-2", "snapshotContentName": "vsc-2", @@ -412,6 +414,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-3", PVCName: "pvc-3", SnapshotDataMoved: true, OperationID: "fake-operation-3", @@ -424,7 +427,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, expect: map[string]interface{}{ "csiSnapshots": map[string]interface{}{ - "pvc-3": map[string]interface{}{ + "pvc-ns-3/pvc-3": map[string]interface{}{ "dataMovement": "included, specify --details for more information", }, }, @@ -435,6 +438,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-4", PVCName: "pvc-4", SnapshotDataMoved: true, OperationID: "fake-operation-4", @@ -448,7 +452,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { inputDetails: true, expect: map[string]interface{}{ "csiSnapshots": map[string]interface{}{ - "pvc-4": map[string]interface{}{ + "pvc-ns-4/pvc-4": map[string]interface{}{ "dataMovement": map[string]interface{}{ "operationID": "fake-operation-4", "dataMover": "velero", @@ -463,6 +467,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { volumeInfo: []*volume.VolumeInfo{ { BackupMethod: volume.CSISnapshot, + PVCNamespace: "pvc-ns-4", PVCName: "pvc-4", SnapshotDataMoved: true, OperationID: "fake-operation-4", @@ -475,7 +480,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { inputDetails: true, expect: map[string]interface{}{ "csiSnapshots": map[string]interface{}{ - "pvc-4": map[string]interface{}{ + "pvc-ns-4/pvc-4": map[string]interface{}{ "dataMovement": map[string]interface{}{ "operationID": "fake-operation-4", "dataMover": "velero",