Skip to content

Commit c080a95

Browse files
authored
Merge branch 'main' into bump-kopia-v0.20.1
2 parents a8f99fa + fbdb74f commit c080a95

9 files changed

Lines changed: 182 additions & 4 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issue #8965, support PVB/PVR's cancel state in the backup/restore

pkg/backup/backup.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ func (kb *kubernetesBackupper) waitUntilPVBsProcessed(ctx context.Context, log l
823823
}
824824
for _, pvb := range pvbs {
825825
pvbMap[pvb] = pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseCompleted ||
826-
pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed
826+
pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed ||
827+
pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseCanceled
827828
}
828829
}
829830

@@ -840,7 +841,8 @@ func (kb *kubernetesBackupper) waitUntilPVBsProcessed(ctx context.Context, log l
840841
continue
841842
}
842843
if updatedPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseCompleted ||
843-
updatedPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed {
844+
updatedPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed ||
845+
updatedPVB.Status.Phase == velerov1api.PodVolumeBackupPhaseCanceled {
844846
pvbMap[pvb] = true
845847
continue
846848
}

pkg/cmd/util/output/backup_describer.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,11 @@ func describePodVolumeBackups(d *Describer, details bool, podVolumeBackups []vel
786786
for _, phase := range []string{
787787
string(velerov1api.PodVolumeBackupPhaseCompleted),
788788
string(velerov1api.PodVolumeBackupPhaseFailed),
789+
string(velerov1api.PodVolumeBackupPhaseCanceled),
789790
"In Progress",
791+
string(velerov1api.PodVolumeBackupPhaseCanceling),
792+
string(velerov1api.PodVolumeBackupPhasePrepared),
793+
string(velerov1api.PodVolumeBackupPhaseAccepted),
790794
string(velerov1api.PodVolumeBackupPhaseNew),
791795
} {
792796
if len(backupsByPhase[phase]) == 0 {
@@ -822,7 +826,11 @@ func groupByPhase(backups []velerov1api.PodVolumeBackup) map[string][]velerov1ap
822826
phaseToGroup := map[velerov1api.PodVolumeBackupPhase]string{
823827
velerov1api.PodVolumeBackupPhaseCompleted: string(velerov1api.PodVolumeBackupPhaseCompleted),
824828
velerov1api.PodVolumeBackupPhaseFailed: string(velerov1api.PodVolumeBackupPhaseFailed),
829+
velerov1api.PodVolumeBackupPhaseCanceled: string(velerov1api.PodVolumeBackupPhaseCanceled),
825830
velerov1api.PodVolumeBackupPhaseInProgress: "In Progress",
831+
velerov1api.PodVolumeBackupPhaseCanceling: string(velerov1api.PodVolumeBackupPhaseCanceling),
832+
velerov1api.PodVolumeBackupPhasePrepared: string(velerov1api.PodVolumeBackupPhasePrepared),
833+
velerov1api.PodVolumeBackupPhaseAccepted: string(velerov1api.PodVolumeBackupPhaseAccepted),
826834
velerov1api.PodVolumeBackupPhaseNew: string(velerov1api.PodVolumeBackupPhaseNew),
827835
"": string(velerov1api.PodVolumeBackupPhaseNew),
828836
}

pkg/cmd/util/output/backup_describer_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,54 @@ func TestDescribePodVolumeBackups(t *testing.T) {
572572
PodName("pod-2").
573573
PodNamespace("pod-ns-1").
574574
SnapshotID("snap-2").Result()
575+
pvb3 := builder.ForPodVolumeBackup("test-ns1", "test-pvb3").
576+
UploaderType("kopia").
577+
Phase(velerov1api.PodVolumeBackupPhaseFailed).
578+
BackupStorageLocation("bsl-1").
579+
Volume("vol-3").
580+
PodName("pod-3").
581+
PodNamespace("pod-ns-1").
582+
SnapshotID("snap-3").Result()
583+
pvb4 := builder.ForPodVolumeBackup("test-ns1", "test-pvb4").
584+
UploaderType("kopia").
585+
Phase(velerov1api.PodVolumeBackupPhaseCanceled).
586+
BackupStorageLocation("bsl-1").
587+
Volume("vol-4").
588+
PodName("pod-4").
589+
PodNamespace("pod-ns-1").
590+
SnapshotID("snap-4").Result()
591+
pvb5 := builder.ForPodVolumeBackup("test-ns1", "test-pvb5").
592+
UploaderType("kopia").
593+
Phase(velerov1api.PodVolumeBackupPhaseInProgress).
594+
BackupStorageLocation("bsl-1").
595+
Volume("vol-5").
596+
PodName("pod-5").
597+
PodNamespace("pod-ns-1").
598+
SnapshotID("snap-5").Result()
599+
pvb6 := builder.ForPodVolumeBackup("test-ns1", "test-pvb6").
600+
UploaderType("kopia").
601+
Phase(velerov1api.PodVolumeBackupPhaseCanceling).
602+
BackupStorageLocation("bsl-1").
603+
Volume("vol-6").
604+
PodName("pod-6").
605+
PodNamespace("pod-ns-1").
606+
SnapshotID("snap-6").Result()
607+
pvb7 := builder.ForPodVolumeBackup("test-ns1", "test-pvb7").
608+
UploaderType("kopia").
609+
Phase(velerov1api.PodVolumeBackupPhasePrepared).
610+
BackupStorageLocation("bsl-1").
611+
Volume("vol-7").
612+
PodName("pod-7").
613+
PodNamespace("pod-ns-1").
614+
SnapshotID("snap-7").Result()
615+
pvb8 := builder.ForPodVolumeBackup("test-ns1", "test-pvb6").
616+
UploaderType("kopia").
617+
Phase(velerov1api.PodVolumeBackupPhaseAccepted).
618+
BackupStorageLocation("bsl-1").
619+
Volume("vol-8").
620+
PodName("pod-8").
621+
PodNamespace("pod-ns-1").
622+
SnapshotID("snap-8").Result()
575623

576624
testcases := []struct {
577625
name string
@@ -602,6 +650,28 @@ func TestDescribePodVolumeBackups(t *testing.T) {
602650
Completed:
603651
pod-ns-1/pod-1: vol-1
604652
pod-ns-1/pod-2: vol-2
653+
`,
654+
},
655+
{
656+
name: "all phases with details",
657+
inputPVBList: []velerov1api.PodVolumeBackup{*pvb1, *pvb2, *pvb3, *pvb4, *pvb5, *pvb6, *pvb7, *pvb8},
658+
inputDetails: true,
659+
expect: ` Pod Volume Backups - kopia:
660+
Completed:
661+
pod-ns-1/pod-1: vol-1
662+
pod-ns-1/pod-2: vol-2
663+
Failed:
664+
pod-ns-1/pod-3: vol-3
665+
Canceled:
666+
pod-ns-1/pod-4: vol-4
667+
In Progress:
668+
pod-ns-1/pod-5: vol-5
669+
Canceling:
670+
pod-ns-1/pod-6: vol-6
671+
Prepared:
672+
pod-ns-1/pod-7: vol-7
673+
Accepted:
674+
pod-ns-1/pod-8: vol-8
605675
`,
606676
},
607677
}

pkg/cmd/util/output/backup_structured_describer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ func describePodVolumeBackupsInSF(backups []velerov1api.PodVolumeBackup, details
499499
for _, phase := range []string{
500500
string(velerov1api.PodVolumeBackupPhaseCompleted),
501501
string(velerov1api.PodVolumeBackupPhaseFailed),
502+
string(velerov1api.PodVolumeBackupPhaseCanceled),
502503
"In Progress",
504+
string(velerov1api.PodVolumeBackupPhaseCanceling),
505+
string(velerov1api.PodVolumeBackupPhasePrepared),
506+
string(velerov1api.PodVolumeBackupPhaseAccepted),
503507
string(velerov1api.PodVolumeBackupPhaseNew),
504508
} {
505509
if len(backupsByPhase[phase]) == 0 {

pkg/cmd/util/output/backup_structured_describer_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,55 @@ func TestDescribePodVolumeBackupsInSF(t *testing.T) {
240240
PodNamespace("pod-ns-1").
241241
SnapshotID("snap-2").Result()
242242

243+
pvb3 := builder.ForPodVolumeBackup("test-ns1", "test-pvb3").
244+
UploaderType("kopia").
245+
Phase(velerov1api.PodVolumeBackupPhaseFailed).
246+
BackupStorageLocation("bsl-1").
247+
Volume("vol-3").
248+
PodName("pod-3").
249+
PodNamespace("pod-ns-1").
250+
SnapshotID("snap-3").Result()
251+
pvb4 := builder.ForPodVolumeBackup("test-ns1", "test-pvb4").
252+
UploaderType("kopia").
253+
Phase(velerov1api.PodVolumeBackupPhaseCanceled).
254+
BackupStorageLocation("bsl-1").
255+
Volume("vol-4").
256+
PodName("pod-4").
257+
PodNamespace("pod-ns-1").
258+
SnapshotID("snap-4").Result()
259+
pvb5 := builder.ForPodVolumeBackup("test-ns1", "test-pvb5").
260+
UploaderType("kopia").
261+
Phase(velerov1api.PodVolumeBackupPhaseInProgress).
262+
BackupStorageLocation("bsl-1").
263+
Volume("vol-5").
264+
PodName("pod-5").
265+
PodNamespace("pod-ns-1").
266+
SnapshotID("snap-5").Result()
267+
pvb6 := builder.ForPodVolumeBackup("test-ns1", "test-pvb6").
268+
UploaderType("kopia").
269+
Phase(velerov1api.PodVolumeBackupPhaseCanceling).
270+
BackupStorageLocation("bsl-1").
271+
Volume("vol-6").
272+
PodName("pod-6").
273+
PodNamespace("pod-ns-1").
274+
SnapshotID("snap-6").Result()
275+
pvb7 := builder.ForPodVolumeBackup("test-ns1", "test-pvb7").
276+
UploaderType("kopia").
277+
Phase(velerov1api.PodVolumeBackupPhasePrepared).
278+
BackupStorageLocation("bsl-1").
279+
Volume("vol-7").
280+
PodName("pod-7").
281+
PodNamespace("pod-ns-1").
282+
SnapshotID("snap-7").Result()
283+
pvb8 := builder.ForPodVolumeBackup("test-ns1", "test-pvb6").
284+
UploaderType("kopia").
285+
Phase(velerov1api.PodVolumeBackupPhaseAccepted).
286+
BackupStorageLocation("bsl-1").
287+
Volume("vol-8").
288+
PodName("pod-8").
289+
PodNamespace("pod-ns-1").
290+
SnapshotID("snap-8").Result()
291+
243292
testcases := []struct {
244293
name string
245294
inputPVBList []velerov1api.PodVolumeBackup
@@ -268,6 +317,40 @@ func TestDescribePodVolumeBackupsInSF(t *testing.T) {
268317
},
269318
},
270319
},
320+
{
321+
name: "all phases",
322+
inputPVBList: []velerov1api.PodVolumeBackup{*pvb1, *pvb2, *pvb3, *pvb4, *pvb5, *pvb6, *pvb7, *pvb8},
323+
inputDetails: true,
324+
expect: map[string]any{
325+
"podVolumeBackups": map[string]any{
326+
"podVolumeBackupsDetails": map[string]any{
327+
"Completed": []map[string]string{
328+
{"pod-ns-1/pod-1": "vol-1"},
329+
{"pod-ns-1/pod-2": "vol-2"},
330+
},
331+
"Failed": []map[string]string{
332+
{"pod-ns-1/pod-3": "vol-3"},
333+
},
334+
"Canceled": []map[string]string{
335+
{"pod-ns-1/pod-4": "vol-4"},
336+
},
337+
"In Progress": []map[string]string{
338+
{"pod-ns-1/pod-5": "vol-5"},
339+
},
340+
"Canceling": []map[string]string{
341+
{"pod-ns-1/pod-6": "vol-6"},
342+
},
343+
"Prepared": []map[string]string{
344+
{"pod-ns-1/pod-7": "vol-7"},
345+
},
346+
"Accepted": []map[string]string{
347+
{"pod-ns-1/pod-8": "vol-8"},
348+
},
349+
},
350+
"uploderType": "kopia",
351+
},
352+
},
353+
},
271354
}
272355
for _, tc := range testcases {
273356
t.Run(tc.name, func(tt *testing.T) {

pkg/cmd/util/output/restore_describer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,11 @@ func describePodVolumeRestores(d *Describer, restores []velerov1api.PodVolumeRes
362362
// go through phases in a specific order
363363
for _, phase := range []string{
364364
string(velerov1api.PodVolumeRestorePhaseCompleted),
365+
string(velerov1api.PodVolumeRestorePhaseCanceled),
365366
string(velerov1api.PodVolumeRestorePhaseFailed),
366367
"In Progress",
368+
string(velerov1api.PodVolumeRestorePhasePrepared),
369+
string(velerov1api.PodVolumeRestorePhaseAccepted),
367370
string(velerov1api.PodVolumeRestorePhaseNew),
368371
} {
369372
if len(restoresByPhase[phase]) == 0 {
@@ -442,8 +445,11 @@ func groupRestoresByPhase(restores []velerov1api.PodVolumeRestore) map[string][]
442445

443446
phaseToGroup := map[velerov1api.PodVolumeRestorePhase]string{
444447
velerov1api.PodVolumeRestorePhaseCompleted: string(velerov1api.PodVolumeRestorePhaseCompleted),
448+
velerov1api.PodVolumeRestorePhaseCanceled: string(velerov1api.PodVolumeRestorePhaseCanceled),
445449
velerov1api.PodVolumeRestorePhaseFailed: string(velerov1api.PodVolumeRestorePhaseFailed),
446450
velerov1api.PodVolumeRestorePhaseInProgress: "In Progress",
451+
velerov1api.PodVolumeRestorePhasePrepared: string(velerov1api.PodVolumeRestorePhasePrepared),
452+
velerov1api.PodVolumeRestorePhaseAccepted: string(velerov1api.PodVolumeRestorePhaseAccepted),
447453
velerov1api.PodVolumeRestorePhaseNew: string(velerov1api.PodVolumeRestorePhaseNew),
448454
"": string(velerov1api.PodVolumeRestorePhaseNew),
449455
}

pkg/podvolume/backupper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,10 @@ func (b *backupper) WaitAllPodVolumesProcessed(log logrus.FieldLogger) []*velero
426426
continue
427427
}
428428
podVolumeBackups = append(podVolumeBackups, pvb)
429-
if pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed || pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseCanceled {
429+
if pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseFailed {
430430
log.Errorf("pod volume backup failed: %s", pvb.Status.Message)
431+
} else if pvb.Status.Phase == velerov1api.PodVolumeBackupPhaseCanceled {
432+
log.Errorf("pod volume backup canceled: %s", pvb.Status.Message)
431433
}
432434
}
433435
}

pkg/podvolume/restorer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ ForEachVolume:
228228
errs = append(errs, errors.New("timed out waiting for all PodVolumeRestores to complete"))
229229
break ForEachVolume
230230
case res := <-resultsChan:
231-
if res.Status.Phase == velerov1api.PodVolumeRestorePhaseFailed || res.Status.Phase == velerov1api.PodVolumeRestorePhaseCanceled {
231+
if res.Status.Phase == velerov1api.PodVolumeRestorePhaseFailed {
232232
errs = append(errs, errors.Errorf("pod volume restore failed: %s", res.Status.Message))
233+
} else if res.Status.Phase == velerov1api.PodVolumeRestorePhaseCanceled {
234+
errs = append(errs, errors.Errorf("pod volume restore canceled: %s", res.Status.Message))
233235
}
234236
tracker.TrackPodVolume(res)
235237
case err := <-r.nodeAgentCheck:

0 commit comments

Comments
 (0)