@@ -63,8 +63,9 @@ func TestControllerFindMachine(t *testing.T) {
63
63
}}
64
64
65
65
test := func (t * testing.T , tc testCase , testConfig * TestConfig ) {
66
- controller , stop := mustCreateTestController (t , testConfig )
67
- defer stop ()
66
+ controller := NewTestMachineController (t )
67
+ defer controller .Stop ()
68
+ controller .AddTestConfigs (testConfig )
68
69
69
70
machine , err := controller .findMachine (path .Join (tc .namespace , tc .name ))
70
71
if err != nil {
@@ -128,8 +129,9 @@ func TestControllerFindMachineOwner(t *testing.T) {
128
129
}).
129
130
Build ()
130
131
131
- controller , stop := mustCreateTestController (t , testConfig )
132
- defer stop ()
132
+ controller := NewTestMachineController (t )
133
+ defer controller .Stop ()
134
+ controller .AddTestConfigs (testConfig )
133
135
134
136
// Test #1: Lookup succeeds
135
137
testResult1 , err := controller .findMachineOwner (testConfig .machines [0 ].DeepCopy ())
@@ -159,7 +161,7 @@ func TestControllerFindMachineOwner(t *testing.T) {
159
161
}
160
162
161
163
// Test #3: Delete the MachineSet and lookup should fail
162
- if err := deleteResource ( controller .managementClient , controller .machineSetInformer , controller .machineSetResource , testConfig .machineSet ); err != nil {
164
+ if err := controller .DeleteResource ( controller .machineSetInformer , controller .machineSetResource , testConfig .machineSet ); err != nil {
163
165
t .Fatalf ("unexpected error, got %v" , err )
164
166
}
165
167
testResult3 , err := controller .findMachineOwner (testConfig .machines [0 ].DeepCopy ())
@@ -181,8 +183,9 @@ func TestControllerFindMachineByProviderID(t *testing.T) {
181
183
}).
182
184
Build ()
183
185
184
- controller , stop := mustCreateTestController (t , testConfig )
185
- defer stop ()
186
+ controller := NewTestMachineController (t )
187
+ defer controller .Stop ()
188
+ controller .AddTestConfigs (testConfig )
186
189
187
190
// Remove all the "machine" annotation values on all the
188
191
// nodes. We want to force findMachineByProviderID() to only
@@ -224,7 +227,7 @@ func TestControllerFindMachineByProviderID(t *testing.T) {
224
227
t .Fatalf ("unexpected error: %v" , err )
225
228
}
226
229
227
- if err := updateResource ( controller .managementClient , controller .machineInformer , controller .machineResource , machine ); err != nil {
230
+ if err := controller .UpdateResource ( controller .machineInformer , controller .machineResource , machine ); err != nil {
228
231
t .Fatalf ("unexpected error updating machine, got %v" , err )
229
232
}
230
233
@@ -247,8 +250,9 @@ func TestControllerFindNodeByNodeName(t *testing.T) {
247
250
}).
248
251
Build ()
249
252
250
- controller , stop := mustCreateTestController (t , testConfig )
251
- defer stop ()
253
+ controller := NewTestMachineController (t )
254
+ defer controller .Stop ()
255
+ controller .AddTestConfigs (testConfig )
252
256
253
257
// Test #1: Verify known node can be found
254
258
node , err := controller .findNodeByNodeName (testConfig .nodes [0 ].Name )
@@ -271,10 +275,11 @@ func TestControllerFindNodeByNodeName(t *testing.T) {
271
275
272
276
func TestControllerListMachinesForScalableResource (t * testing.T ) {
273
277
test := func (t * testing.T , testConfig1 * TestConfig , testConfig2 * TestConfig ) {
274
- controller , stop := mustCreateTestController (t , testConfig1 )
275
- defer stop ()
278
+ controller := NewTestMachineController (t )
279
+ defer controller .Stop ()
280
+ controller .AddTestConfigs (testConfig1 )
276
281
277
- if err := addTestConfigs ( t , controller , testConfig2 ); err != nil {
282
+ if err := controller . AddTestConfigs ( testConfig2 ); err != nil {
278
283
t .Fatalf ("unexpected error: %v" , err )
279
284
}
280
285
@@ -406,8 +411,9 @@ func TestControllerListMachinesForScalableResource(t *testing.T) {
406
411
407
412
func TestControllerLookupNodeGroupForNonExistentNode (t * testing.T ) {
408
413
test := func (t * testing.T , testConfig * TestConfig ) {
409
- controller , stop := mustCreateTestController (t , testConfig )
410
- defer stop ()
414
+ controller := NewTestMachineController (t )
415
+ defer controller .Stop ()
416
+ controller .AddTestConfigs (testConfig )
411
417
412
418
node := testConfig .nodes [0 ].DeepCopy ()
413
419
node .Spec .ProviderID = "does-not-exist"
@@ -452,13 +458,14 @@ func TestControllerLookupNodeGroupForNonExistentNode(t *testing.T) {
452
458
453
459
func TestControllerNodeGroupForNodeWithMissingMachineOwner (t * testing.T ) {
454
460
test := func (t * testing.T , testConfig * TestConfig ) {
455
- controller , stop := mustCreateTestController (t , testConfig )
456
- defer stop ()
461
+ controller := NewTestMachineController (t )
462
+ defer controller .Stop ()
463
+ controller .AddTestConfigs (testConfig )
457
464
458
465
machine := testConfig .machines [0 ].DeepCopy ()
459
466
machine .SetOwnerReferences ([]metav1.OwnerReference {})
460
467
461
- if err := updateResource ( controller .managementClient , controller .machineInformer , controller .machineResource , machine ); err != nil {
468
+ if err := controller .UpdateResource ( controller .machineInformer , controller .machineResource , machine ); err != nil {
462
469
t .Fatalf ("unexpected error updating machine, got %v" , err )
463
470
}
464
471
@@ -507,13 +514,14 @@ func TestControllerNodeGroupForNodeWithMissingSetMachineOwner(t *testing.T) {
507
514
}).
508
515
Build ()
509
516
510
- controller , stop := mustCreateTestController (t , testConfig )
511
- defer stop ()
517
+ controller := NewTestMachineController (t )
518
+ defer controller .Stop ()
519
+ controller .AddTestConfigs (testConfig )
512
520
513
521
machineSet := testConfig .machineSet .DeepCopy ()
514
522
machineSet .SetOwnerReferences ([]metav1.OwnerReference {})
515
523
516
- if err := updateResource ( controller .managementClient , controller .machineSetInformer , controller .machineSetResource , machineSet ); err != nil {
524
+ if err := controller .UpdateResource ( controller .machineSetInformer , controller .machineSetResource , machineSet ); err != nil {
517
525
t .Fatalf ("unexpected error updating machine, got %v" , err )
518
526
}
519
527
@@ -529,8 +537,9 @@ func TestControllerNodeGroupForNodeWithMissingSetMachineOwner(t *testing.T) {
529
537
530
538
func TestControllerNodeGroupForNodeWithPositiveScalingBounds (t * testing.T ) {
531
539
test := func (t * testing.T , testConfig * TestConfig ) {
532
- controller , stop := mustCreateTestController (t , testConfig )
533
- defer stop ()
540
+ controller := NewTestMachineController (t )
541
+ defer controller .Stop ()
542
+ controller .AddTestConfigs (testConfig )
534
543
535
544
ng , err := controller .nodeGroupForNode (testConfig .nodes [0 ])
536
545
if err != nil {
@@ -568,7 +577,7 @@ func TestControllerNodeGroupForNodeWithPositiveScalingBounds(t *testing.T) {
568
577
}
569
578
570
579
func TestControllerNodeGroups (t * testing.T ) {
571
- assertNodegroupLen := func (t * testing.T , controller * machineController , expected int ) {
580
+ assertNodegroupLen := func (t * testing.T , controller * testMachineController , expected int ) {
572
581
t .Helper ()
573
582
nodegroups , err := controller .nodeGroups ()
574
583
if err != nil {
@@ -584,8 +593,8 @@ func TestControllerNodeGroups(t *testing.T) {
584
593
nodeGroupMaxSizeAnnotationKey : "2" ,
585
594
}
586
595
587
- controller , stop := mustCreateTestController (t )
588
- defer stop ()
596
+ controller := NewTestMachineController (t )
597
+ defer controller . Stop ()
589
598
590
599
namespace := RandomString (6 )
591
600
clusterName := RandomString (6 )
@@ -601,7 +610,7 @@ func TestControllerNodeGroups(t *testing.T) {
601
610
WithNodeCount (1 ).
602
611
WithAnnotations (annotations ).
603
612
BuildMultiple (5 )
604
- if err := addTestConfigs ( t , controller , machineSetConfigs ... ); err != nil {
613
+ if err := controller . AddTestConfigs ( machineSetConfigs ... ); err != nil {
605
614
t .Fatalf ("unexpected error: %v" , err )
606
615
}
607
616
assertNodegroupLen (t , controller , 5 )
@@ -614,19 +623,19 @@ func TestControllerNodeGroups(t *testing.T) {
614
623
WithNodeCount (1 ).
615
624
WithAnnotations (annotations ).
616
625
BuildMultiple (2 )
617
- if err := addTestConfigs ( t , controller , machineDeploymentConfigs ... ); err != nil {
626
+ if err := controller . AddTestConfigs ( machineDeploymentConfigs ... ); err != nil {
618
627
t .Fatalf ("unexpected error: %v" , err )
619
628
}
620
629
assertNodegroupLen (t , controller , 7 )
621
630
622
631
// Test #3: delete 5 machineset-backed objects
623
- if err := deleteTestConfigs ( t , controller , machineSetConfigs ... ); err != nil {
632
+ if err := controller . DeleteTestConfigs ( machineSetConfigs ... ); err != nil {
624
633
t .Fatalf ("unexpected error: %v" , err )
625
634
}
626
635
assertNodegroupLen (t , controller , 2 )
627
636
628
637
// Test #4: delete 2 machinedeployment-backed objects
629
- if err := deleteTestConfigs ( t , controller , machineDeploymentConfigs ... ); err != nil {
638
+ if err := controller . DeleteTestConfigs ( machineDeploymentConfigs ... ); err != nil {
630
639
t .Fatalf ("unexpected error: %v" , err )
631
640
}
632
641
assertNodegroupLen (t , controller , 0 )
@@ -644,7 +653,7 @@ func TestControllerNodeGroups(t *testing.T) {
644
653
WithNodeCount (1 ).
645
654
WithAnnotations (annotations ).
646
655
BuildMultiple (5 )
647
- if err := addTestConfigs ( t , controller , machineSetConfigs ... ); err != nil {
656
+ if err := controller . AddTestConfigs ( machineSetConfigs ... ); err != nil {
648
657
t .Fatalf ("unexpected error: %v" , err )
649
658
}
650
659
assertNodegroupLen (t , controller , 5 )
@@ -657,7 +666,7 @@ func TestControllerNodeGroups(t *testing.T) {
657
666
WithNodeCount (1 ).
658
667
WithAnnotations (annotations ).
659
668
BuildMultiple (2 )
660
- if err := addTestConfigs ( t , controller , machineDeploymentConfigs ... ); err != nil {
669
+ if err := controller . AddTestConfigs ( machineDeploymentConfigs ... ); err != nil {
661
670
t .Fatalf ("unexpected error: %v" , err )
662
671
}
663
672
assertNodegroupLen (t , controller , 7 )
@@ -675,7 +684,7 @@ func TestControllerNodeGroups(t *testing.T) {
675
684
WithNodeCount (5 ).
676
685
WithAnnotations (annotations ).
677
686
BuildMultiple (1 )
678
- if err := addTestConfigs ( t , controller , machineSetConfigs ... ); err != nil {
687
+ if err := controller . AddTestConfigs ( machineSetConfigs ... ); err != nil {
679
688
t .Fatalf ("unexpected error: %v" , err )
680
689
}
681
690
if _ , err := controller .nodeGroups (); err == nil {
@@ -690,7 +699,7 @@ func TestControllerNodeGroups(t *testing.T) {
690
699
WithNodeCount (2 ).
691
700
WithAnnotations (annotations ).
692
701
BuildMultiple (1 )
693
- if err := addTestConfigs ( t , controller , machineDeploymentConfigs ... ); err != nil {
702
+ if err := controller . AddTestConfigs ( machineDeploymentConfigs ... ); err != nil {
694
703
t .Fatalf ("unexpected error: %v" , err )
695
704
}
696
705
if _ , err := controller .nodeGroups (); err == nil {
@@ -724,8 +733,9 @@ func TestControllerNodeGroupsNodeCount(t *testing.T) {
724
733
}}
725
734
726
735
test := func (t * testing.T , tc testCase , testConfigs []* TestConfig ) {
727
- controller , stop := mustCreateTestController (t , testConfigs ... )
728
- defer stop ()
736
+ controller := NewTestMachineController (t )
737
+ defer controller .Stop ()
738
+ controller .AddTestConfigs (testConfigs ... )
729
739
730
740
nodegroups , err := controller .nodeGroups ()
731
741
if err != nil {
@@ -784,16 +794,17 @@ func TestControllerFindMachineFromNodeAnnotation(t *testing.T) {
784
794
}).
785
795
Build ()
786
796
787
- controller , stop := mustCreateTestController (t , testConfig )
788
- defer stop ()
797
+ controller := NewTestMachineController (t )
798
+ defer controller .Stop ()
799
+ controller .AddTestConfigs (testConfig )
789
800
790
801
// Remove all the provider ID values on all the machines. We
791
802
// want to force findMachineByProviderID() to fallback to
792
803
// searching using the annotation on the node object.
793
804
for _ , machine := range testConfig .machines {
794
805
unstructured .RemoveNestedField (machine .Object , "spec" , "providerID" )
795
806
796
- if err := updateResource ( controller .managementClient , controller .machineInformer , controller .machineResource , machine ); err != nil {
807
+ if err := controller .UpdateResource ( controller .machineInformer , controller .machineResource , machine ); err != nil {
797
808
t .Fatalf ("unexpected error updating machine, got %v" , err )
798
809
}
799
810
}
@@ -836,8 +847,9 @@ func TestControllerMachineSetNodeNamesWithoutLinkage(t *testing.T) {
836
847
}).
837
848
Build ()
838
849
839
- controller , stop := mustCreateTestController (t , testConfig )
840
- defer stop ()
850
+ controller := NewTestMachineController (t )
851
+ defer controller .Stop ()
852
+ controller .AddTestConfigs (testConfig )
841
853
842
854
// Remove all linkage between node and machine.
843
855
for i := range testConfig .machines {
@@ -846,7 +858,7 @@ func TestControllerMachineSetNodeNamesWithoutLinkage(t *testing.T) {
846
858
unstructured .RemoveNestedField (machine .Object , "spec" , "providerID" )
847
859
unstructured .RemoveNestedField (machine .Object , "status" , "nodeRef" )
848
860
849
- if err := updateResource ( controller .managementClient , controller .machineInformer , controller .machineResource , machine ); err != nil {
861
+ if err := controller .UpdateResource ( controller .machineInformer , controller .machineResource , machine ); err != nil {
850
862
t .Fatalf ("unexpected error updating machine, got %v" , err )
851
863
}
852
864
}
@@ -889,8 +901,9 @@ func TestControllerMachineSetNodeNamesUsingProviderID(t *testing.T) {
889
901
}).
890
902
Build ()
891
903
892
- controller , stop := mustCreateTestController (t , testConfig )
893
- defer stop ()
904
+ controller := NewTestMachineController (t )
905
+ defer controller .Stop ()
906
+ controller .AddTestConfigs (testConfig )
894
907
895
908
nodegroups , err := controller .nodeGroups ()
896
909
if err != nil {
@@ -932,8 +945,9 @@ func TestControllerMachineSetNodeNamesUsingStatusNodeRefName(t *testing.T) {
932
945
}).
933
946
Build ()
934
947
935
- controller , stop := mustCreateTestController (t , testConfig )
936
- defer stop ()
948
+ controller := NewTestMachineController (t )
949
+ defer controller .Stop ()
950
+ controller .AddTestConfigs (testConfig )
937
951
938
952
// Remove all the provider ID values on all the machines. We
939
953
// want to force machineSetNodeNames() to fallback to
@@ -943,7 +957,7 @@ func TestControllerMachineSetNodeNamesUsingStatusNodeRefName(t *testing.T) {
943
957
944
958
unstructured .RemoveNestedField (machine .Object , "spec" , "providerID" )
945
959
946
- if err := updateResource ( controller .managementClient , controller .machineInformer , controller .machineResource , machine ); err != nil {
960
+ if err := controller .UpdateResource ( controller .machineInformer , controller .machineResource , machine ); err != nil {
947
961
t .Fatalf ("unexpected error updating machine, got %v" , err )
948
962
}
949
963
}
@@ -1034,8 +1048,9 @@ func TestControllerGetAPIVersionGroupWithMachineDeployments(t *testing.T) {
1034
1048
machine .SetAPIVersion (fmt .Sprintf ("%s/v1beta1" , customCAPIGroup ))
1035
1049
}
1036
1050
1037
- controller , stop := mustCreateTestController (t , testConfig )
1038
- defer stop ()
1051
+ controller := NewTestMachineController (t )
1052
+ defer controller .Stop ()
1053
+ controller .AddTestConfigs (testConfig )
1039
1054
1040
1055
machineDeployments , err := controller .managementClient .Resource (controller .machineDeploymentResource ).Namespace (testConfig .spec .namespace ).
1041
1056
List (context .TODO (), metav1.ListOptions {})
@@ -1440,8 +1455,9 @@ func Test_machineController_listScalableResources(t *testing.T) {
1440
1455
wantErr : false ,
1441
1456
}} {
1442
1457
t .Run (tc .name , func (t * testing.T ) {
1443
- c , stop := mustCreateTestController (t , allTestConfigs ... )
1444
- defer stop ()
1458
+ c := NewTestMachineController (t )
1459
+ defer c .Stop ()
1460
+ c .AddTestConfigs (allTestConfigs ... )
1445
1461
c .autoDiscoverySpecs = tc .autoDiscoverySpecs
1446
1462
1447
1463
got , err := c .listScalableResources ()
@@ -1554,8 +1570,9 @@ func Test_machineController_nodeGroupForNode(t *testing.T) {
1554
1570
wantErr : false ,
1555
1571
}} {
1556
1572
t .Run (tc .name , func (t * testing.T ) {
1557
- c , stop := mustCreateTestController (t , allTestConfigs ... )
1558
- defer stop ()
1573
+ c := NewTestMachineController (t )
1574
+ defer c .Stop ()
1575
+ c .AddTestConfigs (allTestConfigs ... )
1559
1576
c .autoDiscoverySpecs = tc .autoDiscoverySpecs
1560
1577
1561
1578
got , err := c .nodeGroupForNode (tc .node )
@@ -1692,8 +1709,9 @@ func Test_machineController_nodeGroups(t *testing.T) {
1692
1709
wantErr : false ,
1693
1710
}} {
1694
1711
t .Run (tc .name , func (t * testing.T ) {
1695
- c , stop := mustCreateTestController (t , allTestConfigs ... )
1696
- defer stop ()
1712
+ c := NewTestMachineController (t )
1713
+ defer c .Stop ()
1714
+ c .AddTestConfigs (allTestConfigs ... )
1697
1715
c .autoDiscoverySpecs = tc .autoDiscoverySpecs
1698
1716
1699
1717
got , err := c .nodeGroups ()
0 commit comments