@@ -307,11 +307,12 @@ func TestNamespaceRemapping(t *testing.T) {
307
307
WithFile ("bak/resources/configmaps/namespaces/ns-1/cm-1.json" , newTestConfigMap ().WithNamespace ("ns-1" ).ToJSON ()).
308
308
WithFile ("bak/resources/namespaces/cluster/ns-1.json" , newTestNamespace ("ns-1" ).ToJSON ())
309
309
expectedNS = "ns-2"
310
- expectedObjs = toUnstructured (newTestConfigMap ().WithNamespace ("ns-2" ).WithArkLabel ( "" ). ConfigMap )
310
+ expectedObjs = toUnstructured (newTestConfigMap ().WithNamespace ("ns-2" ).ConfigMap )
311
311
)
312
312
313
313
resourceClient := & arktest.FakeDynamicClient {}
314
314
for i := range expectedObjs {
315
+ addRestoreLabel (& expectedObjs [i ], "" )
315
316
resourceClient .On ("Create" , & expectedObjs [i ]).Return (& expectedObjs [i ], nil )
316
317
}
317
318
@@ -381,8 +382,8 @@ func TestRestoreResourceForNamespace(t *testing.T) {
381
382
WithFile ("configmaps/cm-1.json" , newNamedTestConfigMap ("cm-1" ).ToJSON ()).
382
383
WithFile ("configmaps/cm-2.json" , newNamedTestConfigMap ("cm-2" ).ToJSON ()),
383
384
expectedObjs : toUnstructured (
384
- newNamedTestConfigMap ("cm-1" ).WithArkLabel ( "my-restore" ). ConfigMap ,
385
- newNamedTestConfigMap ("cm-2" ).WithArkLabel ( "my-restore" ). ConfigMap ,
385
+ newNamedTestConfigMap ("cm-1" ).ConfigMap ,
386
+ newNamedTestConfigMap ("cm-2" ).ConfigMap ,
386
387
),
387
388
},
388
389
{
@@ -415,15 +416,15 @@ func TestRestoreResourceForNamespace(t *testing.T) {
415
416
"ns-1" : {"error decoding \" configmaps/cm-1-invalid.json\" : invalid character 'h' in literal true (expecting 'r')" },
416
417
},
417
418
},
418
- expectedObjs : toUnstructured (newNamedTestConfigMap ("cm-2" ).WithArkLabel ( "my-restore" ). ConfigMap ),
419
+ expectedObjs : toUnstructured (newNamedTestConfigMap ("cm-2" ).ConfigMap ),
419
420
},
420
421
{
421
422
name : "matching label selector correctly includes" ,
422
423
namespace : "ns-1" ,
423
424
resourcePath : "configmaps" ,
424
425
labelSelector : labels .SelectorFromSet (labels .Set (map [string ]string {"foo" : "bar" })),
425
426
fileSystem : arktest .NewFakeFileSystem ().WithFile ("configmaps/cm-1.json" , newTestConfigMap ().WithLabels (map [string ]string {"foo" : "bar" }).ToJSON ()),
426
- expectedObjs : toUnstructured (newTestConfigMap ().WithLabels (map [string ]string {"foo" : "bar" }).WithArkLabel ( "my-restore" ). ConfigMap ),
427
+ expectedObjs : toUnstructured (newTestConfigMap ().WithLabels (map [string ]string {"foo" : "bar" }).ConfigMap ),
427
428
},
428
429
{
429
430
name : "non-matching label selector correctly excludes" ,
@@ -440,15 +441,15 @@ func TestRestoreResourceForNamespace(t *testing.T) {
440
441
fileSystem : arktest .NewFakeFileSystem ().
441
442
WithFile ("configmaps/cm-1.json" , newTestConfigMap ().WithControllerOwner ().ToJSON ()).
442
443
WithFile ("configmaps/cm-2.json" , newNamedTestConfigMap ("cm-2" ).ToJSON ()),
443
- expectedObjs : toUnstructured (newNamedTestConfigMap ("cm-2" ).WithArkLabel ( "my-restore" ). ConfigMap ),
444
+ expectedObjs : toUnstructured (newNamedTestConfigMap ("cm-2" ).ConfigMap ),
444
445
},
445
446
{
446
447
name : "namespace is remapped" ,
447
448
namespace : "ns-2" ,
448
449
resourcePath : "configmaps" ,
449
450
labelSelector : labels .NewSelector (),
450
451
fileSystem : arktest .NewFakeFileSystem ().WithFile ("configmaps/cm-1.json" , newTestConfigMap ().WithNamespace ("ns-1" ).ToJSON ()),
451
- expectedObjs : toUnstructured (newTestConfigMap ().WithNamespace ("ns-2" ).WithArkLabel ( "my-restore" ). ConfigMap ),
452
+ expectedObjs : toUnstructured (newTestConfigMap ().WithNamespace ("ns-2" ).ConfigMap ),
452
453
},
453
454
{
454
455
name : "custom restorer is correctly used" ,
@@ -464,7 +465,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
464
465
selector : labels .Everything (),
465
466
},
466
467
},
467
- expectedObjs : toUnstructured (newTestConfigMap ().WithLabels (map [string ]string {"fake-restorer" : "foo" }).WithArkLabel ( "my-restore" ). ConfigMap ),
468
+ expectedObjs : toUnstructured (newTestConfigMap ().WithLabels (map [string ]string {"fake-restorer" : "foo" }).ConfigMap ),
468
469
},
469
470
{
470
471
name : "custom restorer for different group/resource is not used" ,
@@ -480,7 +481,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
480
481
selector : labels .Everything (),
481
482
},
482
483
},
483
- expectedObjs : toUnstructured (newTestConfigMap ().WithArkLabel ( "my-restore" ). ConfigMap ),
484
+ expectedObjs : toUnstructured (newTestConfigMap ().ConfigMap ),
484
485
},
485
486
{
486
487
name : "cluster-scoped resources are skipped when IncludeClusterResources=false" ,
@@ -497,7 +498,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
497
498
labelSelector : labels .NewSelector (),
498
499
includeClusterResources : falsePtr ,
499
500
fileSystem : arktest .NewFakeFileSystem ().WithFile ("configmaps/cm-1.json" , newTestConfigMap ().ToJSON ()),
500
- expectedObjs : toUnstructured (newTestConfigMap ().WithArkLabel ( "my-restore" ). ConfigMap ),
501
+ expectedObjs : toUnstructured (newTestConfigMap ().ConfigMap ),
501
502
},
502
503
{
503
504
name : "cluster-scoped resources are not skipped when IncludeClusterResources=true" ,
@@ -506,7 +507,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
506
507
labelSelector : labels .NewSelector (),
507
508
includeClusterResources : truePtr ,
508
509
fileSystem : arktest .NewFakeFileSystem ().WithFile ("persistentvolumes/pv-1.json" , newTestPV ().ToJSON ()),
509
- expectedObjs : toUnstructured (newTestPV ().WithArkLabel ( "my-restore" ). PersistentVolume ),
510
+ expectedObjs : toUnstructured (newTestPV ().PersistentVolume ),
510
511
},
511
512
{
512
513
name : "namespaced resources are not skipped when IncludeClusterResources=true" ,
@@ -515,7 +516,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
515
516
labelSelector : labels .NewSelector (),
516
517
includeClusterResources : truePtr ,
517
518
fileSystem : arktest .NewFakeFileSystem ().WithFile ("configmaps/cm-1.json" , newTestConfigMap ().ToJSON ()),
518
- expectedObjs : toUnstructured (newTestConfigMap ().WithArkLabel ( "my-restore" ). ConfigMap ),
519
+ expectedObjs : toUnstructured (newTestConfigMap ().ConfigMap ),
519
520
},
520
521
{
521
522
name : "cluster-scoped resources are not skipped when IncludeClusterResources=nil" ,
@@ -524,7 +525,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
524
525
labelSelector : labels .NewSelector (),
525
526
includeClusterResources : nil ,
526
527
fileSystem : arktest .NewFakeFileSystem ().WithFile ("persistentvolumes/pv-1.json" , newTestPV ().ToJSON ()),
527
- expectedObjs : toUnstructured (newTestPV ().WithArkLabel ( "my-restore" ). PersistentVolume ),
528
+ expectedObjs : toUnstructured (newTestPV ().PersistentVolume ),
528
529
},
529
530
{
530
531
name : "namespaced resources are not skipped when IncludeClusterResources=nil" ,
@@ -533,7 +534,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
533
534
labelSelector : labels .NewSelector (),
534
535
includeClusterResources : nil ,
535
536
fileSystem : arktest .NewFakeFileSystem ().WithFile ("configmaps/cm-1.json" , newTestConfigMap ().ToJSON ()),
536
- expectedObjs : toUnstructured (newTestConfigMap ().WithArkLabel ( "my-restore" ). ConfigMap ),
537
+ expectedObjs : toUnstructured (newTestConfigMap ().ConfigMap ),
537
538
},
538
539
{
539
540
name : "serviceaccounts are restored" ,
@@ -542,7 +543,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
542
543
labelSelector : labels .NewSelector (),
543
544
includeClusterResources : nil ,
544
545
fileSystem : arktest .NewFakeFileSystem ().WithFile ("serviceaccounts/sa-1.json" , newTestServiceAccount ().ToJSON ()),
545
- expectedObjs : toUnstructured (newTestServiceAccount ().WithArkLabel ( "my-restore" ). ServiceAccount ),
546
+ expectedObjs : toUnstructured (newTestServiceAccount ().ServiceAccount ),
546
547
},
547
548
{
548
549
name : "non-mirror pods are restored" ,
@@ -566,7 +567,6 @@ func TestRestoreResourceForNamespace(t *testing.T) {
566
567
WithKind ("Pod" ).
567
568
WithNamespace ("ns-1" ).
568
569
WithName ("pod1" ).
569
- WithArkLabel ("my-restore" ).
570
570
Unstructured ),
571
571
},
572
572
},
@@ -594,6 +594,7 @@ func TestRestoreResourceForNamespace(t *testing.T) {
594
594
t .Run (test .name , func (t * testing.T ) {
595
595
resourceClient := & arktest.FakeDynamicClient {}
596
596
for i := range test .expectedObjs {
597
+ addRestoreLabel (& test .expectedObjs [i ], "my-restore" )
597
598
resourceClient .On ("Create" , & test .expectedObjs [i ]).Return (& test .expectedObjs [i ], nil )
598
599
}
599
600
@@ -679,8 +680,7 @@ func TestRestoringExistingServiceAccount(t *testing.T) {
679
680
m [k ] = v
680
681
}
681
682
fromBackupWithLabel := & unstructured.Unstructured {Object : m }
682
- l := map [string ]string {api .RestoreLabelKey : "my-restore" }
683
- fromBackupWithLabel .SetLabels (l )
683
+ addRestoreLabel (fromBackupWithLabel , "my-restore" )
684
684
// resetMetadataAndStatus will strip the creationTimestamp before calling Create
685
685
fromBackupWithLabel .SetCreationTimestamp (metav1.Time {Time : time.Time {}})
686
686
@@ -922,7 +922,7 @@ status:
922
922
}
923
923
924
924
resetMetadataAndStatus (unstructuredPV )
925
- addLabel (unstructuredPV , api . RestoreLabelKey , ctx .restore .Name )
925
+ addRestoreLabel (unstructuredPV , ctx .restore .Name )
926
926
unstructuredPV .Object ["foo" ] = "bar"
927
927
928
928
if test .expectPVCreation {
@@ -964,7 +964,7 @@ status:
964
964
unstructuredPVC := & unstructured.Unstructured {Object : unstructuredPVCMap }
965
965
966
966
resetMetadataAndStatus (unstructuredPVC )
967
- addLabel (unstructuredPVC , api . RestoreLabelKey , ctx .restore .Name )
967
+ addRestoreLabel (unstructuredPVC , ctx .restore .Name )
968
968
969
969
createdPVC := unstructuredPVC .DeepCopy ()
970
970
// just to ensure we have the data flowing correctly
@@ -1422,17 +1422,6 @@ func (obj *testUnstructured) WithName(name string) *testUnstructured {
1422
1422
return obj .WithMetadataField ("name" , name )
1423
1423
}
1424
1424
1425
- func (obj * testUnstructured ) WithArkLabel (restoreName string ) * testUnstructured {
1426
- ls := obj .GetLabels ()
1427
- if ls == nil {
1428
- ls = make (map [string ]string )
1429
- }
1430
- ls [api .RestoreLabelKey ] = restoreName
1431
- obj .SetLabels (ls )
1432
-
1433
- return obj
1434
- }
1435
-
1436
1425
func (obj * testUnstructured ) ToJSON () []byte {
1437
1426
bytes , err := json .Marshal (obj .Object )
1438
1427
if err != nil {
@@ -1514,14 +1503,6 @@ func newTestServiceAccount() *testServiceAccount {
1514
1503
}
1515
1504
}
1516
1505
1517
- func (sa * testServiceAccount ) WithArkLabel (restoreName string ) * testServiceAccount {
1518
- if sa .Labels == nil {
1519
- sa .Labels = make (map [string ]string )
1520
- }
1521
- sa .Labels [api .RestoreLabelKey ] = restoreName
1522
- return sa
1523
- }
1524
-
1525
1506
func (sa * testServiceAccount ) WithImagePullSecret (name string ) * testServiceAccount {
1526
1507
secret := v1.LocalObjectReference {Name : name }
1527
1508
sa .ImagePullSecrets = append (sa .ImagePullSecrets , secret )
@@ -1558,14 +1539,6 @@ func newTestPV() *testPersistentVolume {
1558
1539
}
1559
1540
}
1560
1541
1561
- func (pv * testPersistentVolume ) WithArkLabel (restoreName string ) * testPersistentVolume {
1562
- if pv .Labels == nil {
1563
- pv .Labels = make (map [string ]string )
1564
- }
1565
- pv .Labels [api .RestoreLabelKey ] = restoreName
1566
- return pv
1567
- }
1568
-
1569
1542
func (pv * testPersistentVolume ) ToJSON () []byte {
1570
1543
bytes , _ := json .Marshal (pv .PersistentVolume )
1571
1544
return bytes
@@ -1620,16 +1593,6 @@ func newNamedTestConfigMap(name string) *testConfigMap {
1620
1593
}
1621
1594
}
1622
1595
1623
- func (cm * testConfigMap ) WithArkLabel (restoreName string ) * testConfigMap {
1624
- if cm .Labels == nil {
1625
- cm .Labels = make (map [string ]string )
1626
- }
1627
-
1628
- cm .Labels [api .RestoreLabelKey ] = restoreName
1629
-
1630
- return cm
1631
- }
1632
-
1633
1596
func (cm * testConfigMap ) WithNamespace (name string ) * testConfigMap {
1634
1597
cm .Namespace = name
1635
1598
return cm
0 commit comments