diff --git a/pkg/cmd/util/output/backup_describer.go b/pkg/cmd/util/output/backup_describer.go index 52a29911d..664684cf7 100644 --- a/pkg/cmd/util/output/backup_describer.go +++ b/pkg/cmd/util/output/backup_describer.go @@ -445,6 +445,7 @@ func describeBackupVolumes(ctx context.Context, kbClient kbclient.Client, d *Des nativeSnapshots := []*volume.VolumeInfo{} csiSnapshots := []*volume.VolumeInfo{} + legacyInfoSource := false buf := new(bytes.Buffer) err := downloadrequest.Stream(ctx, kbClient, backup.Namespace, backup.Name, velerov1api.DownloadTargetKindBackupVolumeInfos, buf, downloadRequestTimeout, insecureSkipTLSVerify, caCertPath) @@ -460,6 +461,8 @@ func describeBackupVolumes(ctx context.Context, kbClient kbclient.Client, d *Des d.Printf("\t\n", err) return } + + legacyInfoSource = true } else if err != nil { d.Printf("\t\n", err) return @@ -483,7 +486,7 @@ func describeBackupVolumes(ctx context.Context, kbClient kbclient.Client, d *Des describeNativeSnapshots(d, details, nativeSnapshots) d.Println() - describeCSISnapshots(d, details, csiSnapshots) + describeCSISnapshots(d, details, csiSnapshots, legacyInfoSource) d.Println() describePodVolumeBackups(d, details, podVolumeBackupCRs) @@ -626,13 +629,17 @@ func describNativeSnapshot(d *Describer, details bool, info *volume.VolumeInfo) } } -func describeCSISnapshots(d *Describer, details bool, infos []*volume.VolumeInfo) { +func describeCSISnapshots(d *Describer, details bool, infos []*volume.VolumeInfo, legacyInfoSource bool) { if !features.IsEnabled(velerov1api.CSIFeatureFlag) { return } if len(infos) == 0 { - d.Printf("\tCSI Snapshots: \n") + if legacyInfoSource { + d.Printf("\tCSI Snapshots: \n") + } else { + d.Printf("\tCSI Snapshots: \n") + } return } diff --git a/pkg/cmd/util/output/backup_describer_test.go b/pkg/cmd/util/output/backup_describer_test.go index f3bcd1703..a43ea9584 100644 --- a/pkg/cmd/util/output/backup_describer_test.go +++ b/pkg/cmd/util/output/backup_describer_test.go @@ -379,11 +379,25 @@ func TestCSISnapshots(t *testing.T) { }() testcases := []struct { - name string - volumeInfo []*volume.VolumeInfo - inputDetails bool - expect string + name string + volumeInfo []*volume.VolumeInfo + inputDetails bool + expect string + legacyInfoSource bool }{ + { + name: "empty info, not legacy", + volumeInfo: []*volume.VolumeInfo{}, + expect: ` CSI Snapshots: +`, + }, + { + name: "empty info, legacy", + volumeInfo: []*volume.VolumeInfo{}, + legacyInfoSource: true, + expect: ` CSI Snapshots: +`, + }, { name: "no details, local snapshot", volumeInfo: []*volume.VolumeInfo{ @@ -509,7 +523,7 @@ func TestCSISnapshots(t *testing.T) { buf: &bytes.Buffer{}, } d.out.Init(d.buf, 0, 8, 2, ' ', 0) - describeCSISnapshots(d, tc.inputDetails, tc.volumeInfo) + describeCSISnapshots(d, tc.inputDetails, tc.volumeInfo, tc.legacyInfoSource) d.out.Flush() assert.Equal(t, tc.expect, d.buf.String()) }) diff --git a/pkg/cmd/util/output/backup_structured_describer.go b/pkg/cmd/util/output/backup_structured_describer.go index 4c89b4bec..1f6e7d540 100644 --- a/pkg/cmd/util/output/backup_structured_describer.go +++ b/pkg/cmd/util/output/backup_structured_describer.go @@ -311,6 +311,7 @@ func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, ba nativeSnapshots := []*volume.VolumeInfo{} csiSnapshots := []*volume.VolumeInfo{} + legacyInfoSource := false buf := new(bytes.Buffer) err := downloadrequest.Stream(ctx, kbClient, backup.Namespace, backup.Name, velerov1api.DownloadTargetKindBackupVolumeInfos, buf, downloadRequestTimeout, insecureSkipTLSVerify, caCertPath) @@ -326,6 +327,8 @@ func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, ba backupVolumes["errorConcludeCSISnapshot"] = fmt.Sprintf("error concluding CSI snapshot info: %v", err) return } + + legacyInfoSource = true } else if err != nil { backupVolumes["errorGetBackupVolumeInfo"] = fmt.Sprintf("error getting backup volume info: %v", err) return @@ -348,7 +351,7 @@ func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, ba describeNativeSnapshotsInSF(details, nativeSnapshots, backupVolumes) - describeCSISnapshotsInSF(details, csiSnapshots, backupVolumes) + describeCSISnapshotsInSF(details, csiSnapshots, backupVolumes, legacyInfoSource) describePodVolumeBackupsInSF(podVolumeBackupCRs, details, backupVolumes) @@ -382,13 +385,17 @@ func describNativeSnapshotInSF(details bool, info *volume.VolumeInfo, snapshotDe } } -func describeCSISnapshotsInSF(details bool, infos []*volume.VolumeInfo, backupVolumes map[string]interface{}) { +func describeCSISnapshotsInSF(details bool, infos []*volume.VolumeInfo, backupVolumes map[string]interface{}, legacyInfoSource bool) { if !features.IsEnabled(velerov1api.CSIFeatureFlag) { return } if len(infos) == 0 { - backupVolumes["csiSnapshots"] = "" + if legacyInfoSource { + backupVolumes["csiSnapshots"] = "" + } else { + backupVolumes["csiSnapshots"] = "" + } return } diff --git a/pkg/cmd/util/output/backup_structured_describer_test.go b/pkg/cmd/util/output/backup_structured_describer_test.go index 40501df8d..4dcadacd9 100644 --- a/pkg/cmd/util/output/backup_structured_describer_test.go +++ b/pkg/cmd/util/output/backup_structured_describer_test.go @@ -337,11 +337,27 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }() testcases := []struct { - name string - volumeInfo []*volume.VolumeInfo - inputDetails bool - expect map[string]interface{} + name string + volumeInfo []*volume.VolumeInfo + inputDetails bool + expect map[string]interface{} + legacyInfoSource bool }{ + { + name: "empty info, not legacy", + volumeInfo: []*volume.VolumeInfo{}, + expect: map[string]interface{}{ + "csiSnapshots": "", + }, + }, + { + name: "empty info, legacy", + volumeInfo: []*volume.VolumeInfo{}, + legacyInfoSource: true, + expect: map[string]interface{}{ + "csiSnapshots": "", + }, + }, { name: "no details, local snapshot", volumeInfo: []*volume.VolumeInfo{ @@ -480,7 +496,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(tt *testing.T) { output := make(map[string]interface{}) - describeCSISnapshotsInSF(tc.inputDetails, tc.volumeInfo, output) + describeCSISnapshotsInSF(tc.inputDetails, tc.volumeInfo, output, tc.legacyInfoSource) assert.True(tt, reflect.DeepEqual(output, tc.expect)) }) }