Skip to content

Commit

Permalink
Add nil check for updating DataUpload VolumeInfo in finalizing phase.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Dec 3, 2024
1 parent 7e80d8f commit 226370d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8471-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add nil check for updating DataUpload VolumeInfo in finalizing phase
3 changes: 2 additions & 1 deletion pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ func updateVolumeInfos(

for index := range volumeInfos {
if volumeInfos[index].PVCName == dataUpload.Spec.SourcePVC &&
volumeInfos[index].PVCNamespace == dataUpload.Spec.SourceNamespace {
volumeInfos[index].PVCNamespace == dataUpload.Spec.SourceNamespace &&
volumeInfos[index].SnapshotDataMovementInfo != nil {
if dataUpload.Status.CompletionTimestamp != nil {
volumeInfos[index].CompletionTimestamp = dataUpload.Status.CompletionTimestamp
}
Expand Down
36 changes: 34 additions & 2 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5510,6 +5510,36 @@ func TestUpdateVolumeInfos(t *testing.T) {
},
},
},
{
// This is an error case. No crash happen here is good enough.
name: "VolumeInfo doesn't have SnapshotDataMovementInfo when there is a matching DataUpload",
operations: []*itemoperation.BackupOperation{},
dataUpload: builder.ForDataUpload("velero", "du-1").
CompletionTimestamp(&now).
CSISnapshot(&velerov2alpha1.CSISnapshotSpec{VolumeSnapshot: "vs-1"}).
SnapshotID("snapshot-id").
Progress(shared.DataMoveOperationProgress{TotalBytes: 1000}).
Phase(velerov2alpha1.DataUploadPhaseCompleted).
SourceNamespace("ns-1").
SourcePVC("pvc-1").
Result(),
volumeInfos: []*volume.BackupVolumeInfo{
{
PVCName: "pvc-1",
PVCNamespace: "ns-1",
CompletionTimestamp: &metav1.Time{},
SnapshotDataMovementInfo: nil,
},
},
expectedVolumeInfos: []*volume.BackupVolumeInfo{
{
PVCName: "pvc-1",
PVCNamespace: "ns-1",
CompletionTimestamp: &metav1.Time{},
SnapshotDataMovementInfo: nil,
},
},
},
}

for _, tc := range tests {
Expand All @@ -5526,8 +5556,10 @@ func TestUpdateVolumeInfos(t *testing.T) {
}

require.NoError(t, updateVolumeInfos(tc.volumeInfos, unstructures, tc.operations, logger))
require.Equal(t, tc.expectedVolumeInfos[0].CompletionTimestamp, tc.volumeInfos[0].CompletionTimestamp)
require.Equal(t, tc.expectedVolumeInfos[0].SnapshotDataMovementInfo, tc.volumeInfos[0].SnapshotDataMovementInfo)
if len(tc.expectedVolumeInfos) > 0 {
require.Equal(t, tc.expectedVolumeInfos[0].CompletionTimestamp, tc.volumeInfos[0].CompletionTimestamp)
require.Equal(t, tc.expectedVolumeInfos[0].SnapshotDataMovementInfo, tc.volumeInfos[0].SnapshotDataMovementInfo)
}
})
}
}
Expand Down

0 comments on commit 226370d

Please sign in to comment.