Skip to content

Commit

Permalink
restic: don't try to restore PVBs with no snapshotID
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <[email protected]>
  • Loading branch information
skriss committed Nov 1, 2019
1 parent 83752d2 commit 728930f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
12 changes: 10 additions & 2 deletions pkg/restic/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion pkg/restic/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,25 @@ 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(),
},
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{
Expand Down
2 changes: 2 additions & 0 deletions pkg/restore/restic_restore_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
6 changes: 3 additions & 3 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down

0 comments on commit 728930f

Please sign in to comment.