@@ -1623,6 +1623,11 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
16231623}
16241624
16251625func TestMachineSetReconciler_reconcileUnhealthyMachines (t * testing.T ) {
1626+ // Use a separate scheme for fake client to avoid race conditions with the global scheme.
1627+ scheme := runtime .NewScheme ()
1628+ _ = apiextensionsv1 .AddToScheme (scheme )
1629+ _ = clusterv1 .AddToScheme (scheme )
1630+
16261631 t .Run ("should delete unhealthy machines if preflight checks pass" , func (t * testing.T ) {
16271632 g := NewWithT (t )
16281633
@@ -1692,7 +1697,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
16921697
16931698 machines := []* clusterv1.Machine {unhealthyMachine , healthyMachine }
16941699
1695- fakeClient := fake .NewClientBuilder ().WithObjects (controlPlaneStable , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
1700+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (controlPlaneStable , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
16961701 r := & Reconciler {
16971702 Client : fakeClient ,
16981703 }
@@ -1796,7 +1801,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
17961801 }
17971802
17981803 machines := []* clusterv1.Machine {unhealthyMachine , healthyMachine }
1799- fakeClient := fake .NewClientBuilder ().WithObjects (controlPlaneUpgrading , builder .GenericControlPlaneCRD , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
1804+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (controlPlaneUpgrading , builder .GenericControlPlaneCRD , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
18001805 r := & Reconciler {
18011806 Client : fakeClient ,
18021807 PreflightChecks : sets.Set [clusterv1.MachineSetPreflightCheck ]{}.Insert (clusterv1 .MachineSetPreflightCheckAll ),
@@ -1939,7 +1944,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
19391944 }
19401945
19411946 machines := []* clusterv1.Machine {unhealthyMachine , healthyMachine }
1942- fakeClient := fake .NewClientBuilder ().WithObjects (
1947+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (
19431948 machineDeployment ,
19441949 machineSetOld ,
19451950 machineSetCurrent ,
@@ -2121,7 +2126,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
21212126 },
21222127 }
21232128
2124- fakeClient := fake .NewClientBuilder ().WithObjects (cluster , machineDeployment , healthyMachine ).
2129+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (cluster , machineDeployment , healthyMachine ).
21252130 WithStatusSubresource (& clusterv1.Machine {}, & clusterv1.MachineSet {}, & clusterv1.MachineDeployment {})
21262131 // Create the unhealthy machines.
21272132 for _ , machine := range unhealthyMachines {
0 commit comments