issue 7214: data mover backup describe for legacy backups

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
Lyndon-Li
2023-12-18 11:07:01 +08:00
parent ea6c8ca127
commit 0313c2add0
4 changed files with 60 additions and 16 deletions

View File

@@ -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<error concluding CSI snapshot info: %v>\n", err)
return
}
legacyInfoSource = true
} else if err != nil {
d.Printf("\t<error getting backup volume info: %v>\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: <none included>\n")
if legacyInfoSource {
d.Printf("\tCSI Snapshots: <none included or not detectable>\n")
} else {
d.Printf("\tCSI Snapshots: <none included>\n")
}
return
}

View File

@@ -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: <none included>
`,
},
{
name: "empty info, legacy",
volumeInfo: []*volume.VolumeInfo{},
legacyInfoSource: true,
expect: ` CSI Snapshots: <none included or not detectable>
`,
},
{
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())
})

View File

@@ -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"] = "<none included>"
if legacyInfoSource {
backupVolumes["csiSnapshots"] = "<none included or not detectable>"
} else {
backupVolumes["csiSnapshots"] = "<none included>"
}
return
}

View File

@@ -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": "<none included>",
},
},
{
name: "empty info, legacy",
volumeInfo: []*volume.VolumeInfo{},
legacyInfoSource: true,
expect: map[string]interface{}{
"csiSnapshots": "<none included or not detectable>",
},
},
{
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))
})
}