restic: don't try to restore PVBs with no snapshotID (#2031)

* restic: don't try to restore PVBs with no snapshotID

Signed-off-by: Steve Kriss <krisss@vmware.com>

* changelog

Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
Steve Kriss
2019-11-04 16:18:08 -07:00
committed by GitHub
parent 636a5b9db6
commit 4fb1bc2ef3
5 changed files with 28 additions and 6 deletions

View File

@@ -0,0 +1 @@
bug fix: don't try to restore pod volume backups that don't have a snapshot ID

View File

@@ -87,9 +87,17 @@ func GetVolumeBackupsForPod(podVolumeBackups []*velerov1api.PodVolumeBackup, pod
volumes := make(map[string]string)
for _, pvb := range podVolumeBackups {
if pod.GetName() == pvb.Spec.Pod.Name {
volumes[pvb.Spec.Volume] = pvb.Status.SnapshotID
if pod.GetName() != pvb.Spec.Pod.Name {
continue
}
// skip PVBs without a snapshot ID since there's nothing
// to restore (they could be failed, or for empty volumes).
if pvb.Status.SnapshotID == "" {
continue
}
volumes[pvb.Spec.Volume] = pvb.Status.SnapshotID
}
if len(volumes) > 0 {

View File

@@ -83,7 +83,7 @@ func TestGetVolumeBackupsForPod(t *testing.T) {
expected: map[string]string{"pvbtest1-foo": "bar", "pvbtest2-abc": "123"},
},
{
name: "no snapshot annotation, no suffix, but with PVBs",
name: "no snapshot annotation, but with PVBs",
podVolumeBackups: []*velerov1api.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-1").PodName("TestPod").SnapshotID("bar").Volume("pvbtest1-foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-2").PodName("TestPod").SnapshotID("123").Volume("pvbtest2-abc").Result(),
@@ -91,6 +91,17 @@ func TestGetVolumeBackupsForPod(t *testing.T) {
podName: "TestPod",
expected: map[string]string{"pvbtest1-foo": "bar", "pvbtest2-abc": "123"},
},
{
name: "no snapshot annotation, but with PVBs, some of which have snapshot IDs and some of which don't",
podVolumeBackups: []*velerov1api.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-1").PodName("TestPod").SnapshotID("bar").Volume("pvbtest1-foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-2").PodName("TestPod").SnapshotID("123").Volume("pvbtest2-abc").Result(),
builder.ForPodVolumeBackup("velero", "pvb-3").PodName("TestPod").Volume("pvbtest3-foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-4").PodName("TestPod").Volume("pvbtest4-abc").Result(),
},
podName: "TestPod",
expected: map[string]string{"pvbtest1-foo": "bar", "pvbtest2-abc": "123"},
},
{
name: "has snapshot annotation, with suffix, and with PVBs from current pod and a PVB from another pod",
podVolumeBackups: []*velerov1api.PodVolumeBackup{

View File

@@ -158,11 +158,13 @@ func TestResticRestoreActionExecute(t *testing.T) {
PodName("my-pod").
Volume("vol-1").
ObjectMeta(builder.WithLabels(velerov1api.BackupNameLabel, backupName)).
SnapshotID("foo").
Result(),
builder.ForPodVolumeBackup(veleroNs, "pvb-2").
PodName("my-pod").
Volume("vol-2").
ObjectMeta(builder.WithLabels(velerov1api.BackupNameLabel, backupName)).
SnapshotID("foo").
Result(),
},
want: builder.ForPod("ns-1", "my-pod").

View File

@@ -2277,9 +2277,9 @@ func TestRestoreWithRestic(t *testing.T) {
backup: defaultBackup().Result(),
apiResources: []*test.APIResource{test.Pods()},
podVolumeBackups: []*velerov1api.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-1").PodName("pod-1").Result(),
builder.ForPodVolumeBackup("velero", "pvb-2").PodName("pod-2").Result(),
builder.ForPodVolumeBackup("velero", "pvb-3").PodName("pod-4").Result(),
builder.ForPodVolumeBackup("velero", "pvb-1").PodName("pod-1").SnapshotID("foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-2").PodName("pod-2").SnapshotID("foo").Result(),
builder.ForPodVolumeBackup("velero", "pvb-3").PodName("pod-4").SnapshotID("foo").Result(),
},
podWithPVBs: []*corev1api.Pod{
builder.ForPod("ns-1", "pod-2").