Skip to content

Commit 04d6c79

Browse files
authored
Merge pull request #8471 from vmware-tanzu/8440_fix_main
[main] Add nil check for updating DataUpload VolumeInfo in finalizing phase
2 parents 6c0ed1e + 226370d commit 04d6c79

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add nil check for updating DataUpload VolumeInfo in finalizing phase

pkg/backup/backup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,8 @@ func updateVolumeInfos(
10581058

10591059
for index := range volumeInfos {
10601060
if volumeInfos[index].PVCName == dataUpload.Spec.SourcePVC &&
1061-
volumeInfos[index].PVCNamespace == dataUpload.Spec.SourceNamespace {
1061+
volumeInfos[index].PVCNamespace == dataUpload.Spec.SourceNamespace &&
1062+
volumeInfos[index].SnapshotDataMovementInfo != nil {
10621063
if dataUpload.Status.CompletionTimestamp != nil {
10631064
volumeInfos[index].CompletionTimestamp = dataUpload.Status.CompletionTimestamp
10641065
}

pkg/backup/backup_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5545,6 +5545,36 @@ func TestUpdateVolumeInfos(t *testing.T) {
55455545
},
55465546
},
55475547
},
5548+
{
5549+
// This is an error case. No crash happen here is good enough.
5550+
name: "VolumeInfo doesn't have SnapshotDataMovementInfo when there is a matching DataUpload",
5551+
operations: []*itemoperation.BackupOperation{},
5552+
dataUpload: builder.ForDataUpload("velero", "du-1").
5553+
CompletionTimestamp(&now).
5554+
CSISnapshot(&velerov2alpha1.CSISnapshotSpec{VolumeSnapshot: "vs-1"}).
5555+
SnapshotID("snapshot-id").
5556+
Progress(shared.DataMoveOperationProgress{TotalBytes: 1000}).
5557+
Phase(velerov2alpha1.DataUploadPhaseCompleted).
5558+
SourceNamespace("ns-1").
5559+
SourcePVC("pvc-1").
5560+
Result(),
5561+
volumeInfos: []*volume.BackupVolumeInfo{
5562+
{
5563+
PVCName: "pvc-1",
5564+
PVCNamespace: "ns-1",
5565+
CompletionTimestamp: &metav1.Time{},
5566+
SnapshotDataMovementInfo: nil,
5567+
},
5568+
},
5569+
expectedVolumeInfos: []*volume.BackupVolumeInfo{
5570+
{
5571+
PVCName: "pvc-1",
5572+
PVCNamespace: "ns-1",
5573+
CompletionTimestamp: &metav1.Time{},
5574+
SnapshotDataMovementInfo: nil,
5575+
},
5576+
},
5577+
},
55485578
}
55495579

55505580
for _, tc := range tests {
@@ -5561,8 +5591,10 @@ func TestUpdateVolumeInfos(t *testing.T) {
55615591
}
55625592

55635593
require.NoError(t, updateVolumeInfos(tc.volumeInfos, unstructures, tc.operations, logger))
5564-
require.Equal(t, tc.expectedVolumeInfos[0].CompletionTimestamp, tc.volumeInfos[0].CompletionTimestamp)
5565-
require.Equal(t, tc.expectedVolumeInfos[0].SnapshotDataMovementInfo, tc.volumeInfos[0].SnapshotDataMovementInfo)
5594+
if len(tc.expectedVolumeInfos) > 0 {
5595+
require.Equal(t, tc.expectedVolumeInfos[0].CompletionTimestamp, tc.volumeInfos[0].CompletionTimestamp)
5596+
require.Equal(t, tc.expectedVolumeInfos[0].SnapshotDataMovementInfo, tc.volumeInfos[0].SnapshotDataMovementInfo)
5597+
}
55665598
})
55675599
}
55685600
}

0 commit comments

Comments
 (0)