mirror of
https://github.com/vmware-tanzu/velero.git
synced 2025-12-23 14:25:22 +00:00
issue 7214: data mover backup describe for legacy backups
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
@@ -445,6 +445,7 @@ func describeBackupVolumes(ctx context.Context, kbClient kbclient.Client, d *Des
|
|||||||
|
|
||||||
nativeSnapshots := []*volume.VolumeInfo{}
|
nativeSnapshots := []*volume.VolumeInfo{}
|
||||||
csiSnapshots := []*volume.VolumeInfo{}
|
csiSnapshots := []*volume.VolumeInfo{}
|
||||||
|
legacyInfoSource := false
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := downloadrequest.Stream(ctx, kbClient, backup.Namespace, backup.Name, velerov1api.DownloadTargetKindBackupVolumeInfos, buf, downloadRequestTimeout, insecureSkipTLSVerify, caCertPath)
|
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)
|
d.Printf("\t<error concluding CSI snapshot info: %v>\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyInfoSource = true
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
d.Printf("\t<error getting backup volume info: %v>\n", err)
|
d.Printf("\t<error getting backup volume info: %v>\n", err)
|
||||||
return
|
return
|
||||||
@@ -483,7 +486,7 @@ func describeBackupVolumes(ctx context.Context, kbClient kbclient.Client, d *Des
|
|||||||
describeNativeSnapshots(d, details, nativeSnapshots)
|
describeNativeSnapshots(d, details, nativeSnapshots)
|
||||||
d.Println()
|
d.Println()
|
||||||
|
|
||||||
describeCSISnapshots(d, details, csiSnapshots)
|
describeCSISnapshots(d, details, csiSnapshots, legacyInfoSource)
|
||||||
d.Println()
|
d.Println()
|
||||||
|
|
||||||
describePodVolumeBackups(d, details, podVolumeBackupCRs)
|
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) {
|
if !features.IsEnabled(velerov1api.CSIFeatureFlag) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(infos) == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -379,11 +379,25 @@ func TestCSISnapshots(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
volumeInfo []*volume.VolumeInfo
|
volumeInfo []*volume.VolumeInfo
|
||||||
inputDetails bool
|
inputDetails bool
|
||||||
expect string
|
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",
|
name: "no details, local snapshot",
|
||||||
volumeInfo: []*volume.VolumeInfo{
|
volumeInfo: []*volume.VolumeInfo{
|
||||||
@@ -509,7 +523,7 @@ func TestCSISnapshots(t *testing.T) {
|
|||||||
buf: &bytes.Buffer{},
|
buf: &bytes.Buffer{},
|
||||||
}
|
}
|
||||||
d.out.Init(d.buf, 0, 8, 2, ' ', 0)
|
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()
|
d.out.Flush()
|
||||||
assert.Equal(t, tc.expect, d.buf.String())
|
assert.Equal(t, tc.expect, d.buf.String())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, ba
|
|||||||
|
|
||||||
nativeSnapshots := []*volume.VolumeInfo{}
|
nativeSnapshots := []*volume.VolumeInfo{}
|
||||||
csiSnapshots := []*volume.VolumeInfo{}
|
csiSnapshots := []*volume.VolumeInfo{}
|
||||||
|
legacyInfoSource := false
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := downloadrequest.Stream(ctx, kbClient, backup.Namespace, backup.Name, velerov1api.DownloadTargetKindBackupVolumeInfos, buf, downloadRequestTimeout, insecureSkipTLSVerify, caCertPath)
|
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)
|
backupVolumes["errorConcludeCSISnapshot"] = fmt.Sprintf("error concluding CSI snapshot info: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyInfoSource = true
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
backupVolumes["errorGetBackupVolumeInfo"] = fmt.Sprintf("error getting backup volume info: %v", err)
|
backupVolumes["errorGetBackupVolumeInfo"] = fmt.Sprintf("error getting backup volume info: %v", err)
|
||||||
return
|
return
|
||||||
@@ -348,7 +351,7 @@ func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, ba
|
|||||||
|
|
||||||
describeNativeSnapshotsInSF(details, nativeSnapshots, backupVolumes)
|
describeNativeSnapshotsInSF(details, nativeSnapshots, backupVolumes)
|
||||||
|
|
||||||
describeCSISnapshotsInSF(details, csiSnapshots, backupVolumes)
|
describeCSISnapshotsInSF(details, csiSnapshots, backupVolumes, legacyInfoSource)
|
||||||
|
|
||||||
describePodVolumeBackupsInSF(podVolumeBackupCRs, details, backupVolumes)
|
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) {
|
if !features.IsEnabled(velerov1api.CSIFeatureFlag) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(infos) == 0 {
|
if len(infos) == 0 {
|
||||||
backupVolumes["csiSnapshots"] = "<none included>"
|
if legacyInfoSource {
|
||||||
|
backupVolumes["csiSnapshots"] = "<none included or not detectable>"
|
||||||
|
} else {
|
||||||
|
backupVolumes["csiSnapshots"] = "<none included>"
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -337,11 +337,27 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
volumeInfo []*volume.VolumeInfo
|
volumeInfo []*volume.VolumeInfo
|
||||||
inputDetails bool
|
inputDetails bool
|
||||||
expect map[string]interface{}
|
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",
|
name: "no details, local snapshot",
|
||||||
volumeInfo: []*volume.VolumeInfo{
|
volumeInfo: []*volume.VolumeInfo{
|
||||||
@@ -480,7 +496,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
|
|||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
t.Run(tc.name, func(tt *testing.T) {
|
t.Run(tc.name, func(tt *testing.T) {
|
||||||
output := make(map[string]interface{})
|
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))
|
assert.True(tt, reflect.DeepEqual(output, tc.expect))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user