@@ -238,6 +238,8 @@ func TestRestoreReconcile(t *testing.T) {
238238 expectedFinalPhase string
239239 addValidFinalizer bool
240240 emptyVolumeInfo bool
241+ podVolumeBackups []* velerov1api.PodVolumeBackup
242+ expectedPVBCount int
241243 }{
242244 {
243245 name : "restore with both namespace in both includedNamespaces and excludedNamespaces fails validation" ,
@@ -357,6 +359,22 @@ func TestRestoreReconcile(t *testing.T) {
357359 expectedCompletedTime : & timestamp ,
358360 expectedRestorerCall : NewRestore ("foo" , "bar" , "backup-1" , "ns-1" , "" , velerov1api .RestorePhaseInProgress ).Result (),
359361 },
362+ {
363+ name : "valid restore gets executed and only includes pod volume backups from restore namespace" ,
364+ location : defaultStorageLocation ,
365+ restore : NewRestore ("foo" , "bar2" , "backup-1" , "ns-1" , "" , velerov1api .RestorePhaseNew ).Result (),
366+ backup : defaultBackup ().StorageLocation ("default" ).Result (),
367+ podVolumeBackups : []* velerov1api.PodVolumeBackup {
368+ builder .ForPodVolumeBackup ("foo" , "pvb-1" ).ObjectMeta (builder .WithLabels (velerov1api .BackupNameLabel , "backup-1" )).Result (),
369+ builder .ForPodVolumeBackup ("other-ns" , "pvb-2" ).ObjectMeta (builder .WithLabels (velerov1api .BackupNameLabel , "backup-1" )).Result (),
370+ },
371+ expectedPVBCount : 1 ,
372+ expectedErr : false ,
373+ expectedPhase : string (velerov1api .RestorePhaseInProgress ),
374+ expectedStartTime : & timestamp ,
375+ expectedCompletedTime : & timestamp ,
376+ expectedRestorerCall : NewRestore ("foo" , "bar2" , "backup-1" , "ns-1" , "" , velerov1api .RestorePhaseInProgress ).Result (),
377+ },
360378 {
361379 name : "restoration of nodes is not supported" ,
362380 location : defaultStorageLocation ,
@@ -501,6 +519,13 @@ func TestRestoreReconcile(t *testing.T) {
501519 defaultStorageLocation .ObjectMeta .ResourceVersion = ""
502520 }()
503521
522+ if test .podVolumeBackups != nil {
523+ for _ , pvb := range test .podVolumeBackups {
524+ err := fakeClient .Create (t .Context (), pvb )
525+ require .NoError (t , err )
526+ }
527+ }
528+
504529 r := NewRestoreReconciler (
505530 t .Context (),
506531 velerov1api .DefaultNamespace ,
@@ -670,6 +695,10 @@ func TestRestoreReconcile(t *testing.T) {
670695 // the mock stores the pointer, which gets modified after
671696 assert .Equal (t , test .expectedRestorerCall .Spec , restorer .calledWithArg .Spec )
672697 assert .Equal (t , test .expectedRestorerCall .Status .Phase , restorer .calledWithArg .Status .Phase )
698+
699+ if test .podVolumeBackups != nil {
700+ assert .Len (t , restorer .calledWithPVBs , test .expectedPVBCount )
701+ }
673702 })
674703 }
675704}
@@ -1021,8 +1050,9 @@ func NewRestore(ns, name, backup, includeNS, includeResource string, phase veler
10211050
10221051type fakeRestorer struct {
10231052 mock.Mock
1024- calledWithArg velerov1api.Restore
1025- kbClient client.Client
1053+ calledWithArg velerov1api.Restore
1054+ calledWithPVBs []* velerov1api.PodVolumeBackup
1055+ kbClient client.Client
10261056}
10271057
10281058func (r * fakeRestorer ) Restore (
@@ -1045,6 +1075,7 @@ func (r *fakeRestorer) RestoreWithResolvers(req *pkgrestore.Request,
10451075 r .kbClient , volumeSnapshotterGetter )
10461076
10471077 r .calledWithArg = * req .Restore
1078+ r .calledWithPVBs = req .PodVolumeBackups
10481079
10491080 return res .Get (0 ).(results.Result ), res .Get (1 ).(results.Result )
10501081}
0 commit comments