Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#5769 from Lyndon-Li/issue-fix-5458
Browse files Browse the repository at this point in the history
Issue fix 5458
  • Loading branch information
Lyndon-Li authored Feb 8, 2023
2 parents 6257060 + 2574229 commit 7139daf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5769-Lyndon-Li
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue 5458, track pod volume backup until the CR is submitted in case it is skipped half way
10 changes: 5 additions & 5 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ type fakePodVolumeBackupper struct{}
func (b *fakePodVolumeBackupper) BackupPodVolumes(backup *velerov1.Backup, pod *corev1.Pod, volumes []string, _ logrus.FieldLogger) ([]*velerov1.PodVolumeBackup, []error) {
var res []*velerov1.PodVolumeBackup
for _, vol := range volumes {
pvb := builder.ForPodVolumeBackup("velero", fmt.Sprintf("pvb-%s-%s-%s", pod.Namespace, pod.Name, vol)).Result()
pvb := builder.ForPodVolumeBackup("velero", fmt.Sprintf("pvb-%s-%s-%s", pod.Namespace, pod.Name, vol)).Volume(vol).Result()
res = append(res, pvb)
}

Expand Down Expand Up @@ -2654,7 +2654,7 @@ func TestBackupWithPodVolume(t *testing.T) {
),
},
want: []*velerov1.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-foo").Volume("foo").Result(),
},
},
{
Expand All @@ -2675,7 +2675,7 @@ func TestBackupWithPodVolume(t *testing.T) {
),
},
want: []*velerov1.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-foo").Volume("foo").Result(),
},
},
{
Expand Down Expand Up @@ -2710,8 +2710,8 @@ func TestBackupWithPodVolume(t *testing.T) {
WithVolume("pv-2", "vol-2", "", "type-1", 100, false),
},
want: []*velerov1.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-vol-1").Result(),
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-vol-2").Result(),
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-vol-1").Volume("vol-1").Result(),
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-vol-2").Volume("vol-2").Result(),
},
},
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr

pvbVolumes = append(pvbVolumes, volume)
}

// track the volumes that are PVCs using the PVC snapshot tracker, so that when we backup PVCs/PVs
// via an item action in the next step, we don't snapshot PVs that will have their data backed up
// with pod volume backup.
ib.podVolumeSnapshotTracker.Track(pod, pvbVolumes)
}
}

Expand Down Expand Up @@ -211,6 +206,13 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr

ib.backupRequest.PodVolumeBackups = append(ib.backupRequest.PodVolumeBackups, podVolumeBackups...)
backupErrs = append(backupErrs, errs...)

// track the volumes that are PVCs using the PVC snapshot tracker, so that when we backup PVCs/PVs
// via an item action in the next step, we don't snapshot PVs that will have their data backed up
// with pod volume backup.
for _, pvb := range podVolumeBackups {
ib.podVolumeSnapshotTracker.Track(pod, []string{pvb.Spec.Volume})
}
}

log.Debug("Executing post hooks")
Expand Down

0 comments on commit 7139daf

Please sign in to comment.