@@ -389,12 +389,14 @@ func TestMachineFinalizer(t *testing.T) {
389389 t .Run (tc .name , func (t * testing.T ) {
390390 g := NewWithT (t )
391391
392+ c := fake .NewClientBuilder ().WithObjects (
393+ clusterCorrectMeta ,
394+ machineValidCluster ,
395+ machineWithFinalizer ,
396+ ).Build ()
392397 mr := & Reconciler {
393- Client : fake .NewClientBuilder ().WithObjects (
394- clusterCorrectMeta ,
395- machineValidCluster ,
396- machineWithFinalizer ,
397- ).Build (),
398+ Client : c ,
399+ UnstructuredCachingClient : c ,
398400 }
399401
400402 _ , _ = mr .Reconcile (ctx , tc .request )
@@ -556,8 +558,9 @@ func TestMachineOwnerReference(t *testing.T) {
556558 machineValidControlled ,
557559 ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
558560 mr := & Reconciler {
559- Client : c ,
560- APIReader : c ,
561+ Client : c ,
562+ UnstructuredCachingClient : c ,
563+ APIReader : c ,
561564 }
562565
563566 key := client.ObjectKey {Namespace : tc .m .Namespace , Name : tc .m .Name }
@@ -727,9 +730,10 @@ func TestReconcileRequest(t *testing.T) {
727730 ).WithStatusSubresource (& clusterv1.Machine {}).WithIndex (& corev1.Node {}, index .NodeProviderIDField , index .NodeByProviderID ).Build ()
728731
729732 r := & Reconciler {
730- Client : clientFake ,
731- Tracker : remote .NewTestClusterCacheTracker (logr .New (log.NullLogSink {}), clientFake , scheme .Scheme , client.ObjectKey {Name : testCluster .Name , Namespace : testCluster .Namespace }),
732- ssaCache : ssa .NewCache (),
733+ Client : clientFake ,
734+ UnstructuredCachingClient : clientFake ,
735+ Tracker : remote .NewTestClusterCacheTracker (logr .New (log.NullLogSink {}), clientFake , scheme .Scheme , client.ObjectKey {Name : testCluster .Name , Namespace : testCluster .Namespace }),
736+ ssaCache : ssa .NewCache (),
733737 }
734738
735739 result , err := r .Reconcile (ctx , reconcile.Request {NamespacedName : util .ObjectKey (& tc .machine )})
@@ -975,9 +979,10 @@ func TestMachineConditions(t *testing.T) {
975979 Build ()
976980
977981 r := & Reconciler {
978- Client : clientFake ,
979- Tracker : remote .NewTestClusterCacheTracker (logr .New (log.NullLogSink {}), clientFake , scheme .Scheme , client.ObjectKey {Name : testCluster .Name , Namespace : testCluster .Namespace }),
980- ssaCache : ssa .NewCache (),
982+ Client : clientFake ,
983+ UnstructuredCachingClient : clientFake ,
984+ Tracker : remote .NewTestClusterCacheTracker (logr .New (log.NullLogSink {}), clientFake , scheme .Scheme , client.ObjectKey {Name : testCluster .Name , Namespace : testCluster .Namespace }),
985+ ssaCache : ssa .NewCache (),
981986 }
982987
983988 _ , err := r .Reconcile (ctx , reconcile.Request {NamespacedName : util .ObjectKey (& machine )})
@@ -1064,8 +1069,10 @@ func TestReconcileDeleteExternal(t *testing.T) {
10641069 objs = append (objs , bootstrapConfig )
10651070 }
10661071
1072+ c := fake .NewClientBuilder ().WithObjects (objs ... ).Build ()
10671073 r := & Reconciler {
1068- Client : fake .NewClientBuilder ().WithObjects (objs ... ).Build (),
1074+ Client : c ,
1075+ UnstructuredCachingClient : c ,
10691076 }
10701077
10711078 obj , err := r .reconcileDeleteExternal (ctx , machine , machine .Spec .Bootstrap .ConfigRef )
@@ -1106,8 +1113,10 @@ func TestRemoveMachineFinalizerAfterDeleteReconcile(t *testing.T) {
11061113 },
11071114 }
11081115 key := client.ObjectKey {Namespace : m .Namespace , Name : m .Name }
1116+ c := fake .NewClientBuilder ().WithObjects (testCluster , m ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
11091117 mr := & Reconciler {
1110- Client : fake .NewClientBuilder ().WithObjects (testCluster , m ).WithStatusSubresource (& clusterv1.Machine {}).Build (),
1118+ Client : c ,
1119+ UnstructuredCachingClient : c ,
11111120 }
11121121 _ , err := mr .Reconcile (ctx , reconcile.Request {NamespacedName : key })
11131122 g .Expect (err ).ToNot (HaveOccurred ())
@@ -1232,8 +1241,10 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
12321241 var objs []client.Object
12331242 objs = append (objs , testCluster , tt .machine )
12341243
1244+ c := fake .NewClientBuilder ().WithObjects (objs ... ).Build ()
12351245 r := & Reconciler {
1236- Client : fake .NewClientBuilder ().WithObjects (objs ... ).Build (),
1246+ Client : c ,
1247+ UnstructuredCachingClient : c ,
12371248 }
12381249
12391250 got := r .isNodeDrainAllowed (tt .machine )
@@ -1357,8 +1368,10 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
13571368 var objs []client.Object
13581369 objs = append (objs , testCluster , tt .machine )
13591370
1371+ c := fake .NewClientBuilder ().WithObjects (objs ... ).Build ()
13601372 r := & Reconciler {
1361- Client : fake .NewClientBuilder ().WithObjects (objs ... ).Build (),
1373+ Client : c ,
1374+ UnstructuredCachingClient : c ,
13621375 }
13631376
13641377 got := r .isNodeVolumeDetachingAllowed (tt .machine )
@@ -1709,16 +1722,18 @@ func TestIsDeleteNodeAllowed(t *testing.T) {
17091722 m2 .Labels [clusterv1 .MachineControlPlaneLabel ] = ""
17101723 }
17111724
1725+ c := fake .NewClientBuilder ().WithObjects (
1726+ tc .cluster ,
1727+ tc .machine ,
1728+ m1 ,
1729+ m2 ,
1730+ emp ,
1731+ mcpBeingDeleted ,
1732+ empBeingDeleted ,
1733+ ).Build ()
17121734 mr := & Reconciler {
1713- Client : fake .NewClientBuilder ().WithObjects (
1714- tc .cluster ,
1715- tc .machine ,
1716- m1 ,
1717- m2 ,
1718- emp ,
1719- mcpBeingDeleted ,
1720- empBeingDeleted ,
1721- ).Build (),
1735+ Client : c ,
1736+ UnstructuredCachingClient : c ,
17221737 }
17231738
17241739 err := mr .isDeleteNodeAllowed (ctx , tc .cluster , tc .machine )
@@ -1981,7 +1996,8 @@ func TestNodeToMachine(t *testing.T) {
19811996 }
19821997
19831998 r := & Reconciler {
1984- Client : env ,
1999+ Client : env ,
2000+ UnstructuredCachingClient : env ,
19852001 }
19862002 for _ , node := range fakeNodes {
19872003 request := r .nodeToMachine (ctx , node )
@@ -2159,10 +2175,11 @@ func TestNodeDeletion(t *testing.T) {
21592175 tracker := remote .NewTestClusterCacheTracker (ctrl .Log , fakeClient , fakeScheme , client .ObjectKeyFromObject (& testCluster ))
21602176
21612177 r := & Reconciler {
2162- Client : fakeClient ,
2163- Tracker : tracker ,
2164- recorder : record .NewFakeRecorder (10 ),
2165- nodeDeletionRetryTimeout : 10 * time .Millisecond ,
2178+ Client : fakeClient ,
2179+ UnstructuredCachingClient : fakeClient ,
2180+ Tracker : tracker ,
2181+ recorder : record .NewFakeRecorder (10 ),
2182+ nodeDeletionRetryTimeout : 10 * time .Millisecond ,
21662183 }
21672184
21682185 cluster := testCluster .DeepCopy ()
0 commit comments