Merge pull request #5769 from Lyndon-Li/issue-fix-5458

Issue fix 5458
pull/5843/head
lyndon 2023-02-08 09:59:15 +08:00 committed by GitHub
commit 7139daf07a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -0,0 +1 @@
Fix issue 5458, track pod volume backup until the CR is submitted in case it is skipped half way

View File

@ -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)
}
@ -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(),
},
},
{
@ -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(),
},
},
{
@ -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(),
},
},
}

View File

@ -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)
}
}
@ -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")