@@ -1618,6 +1618,11 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
16181618}
16191619
16201620func TestMachineSetReconciler_reconcileUnhealthyMachines (t * testing.T ) {
1621+ // Use a separate scheme for fake client to avoid race conditions with the global scheme.
1622+ scheme := runtime .NewScheme ()
1623+ _ = apiextensionsv1 .AddToScheme (scheme )
1624+ _ = clusterv1 .AddToScheme (scheme )
1625+
16211626 t .Run ("should delete unhealthy machines if preflight checks pass" , func (t * testing.T ) {
16221627 g := NewWithT (t )
16231628
@@ -1687,7 +1692,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
16871692
16881693 machines := []* clusterv1.Machine {unhealthyMachine , healthyMachine }
16891694
1690- fakeClient := fake .NewClientBuilder ().WithObjects (controlPlaneStable , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
1695+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (controlPlaneStable , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
16911696 r := & Reconciler {
16921697 Client : fakeClient ,
16931698 }
@@ -1791,7 +1796,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
17911796 }
17921797
17931798 machines := []* clusterv1.Machine {unhealthyMachine , healthyMachine }
1794- fakeClient := fake .NewClientBuilder ().WithObjects (controlPlaneUpgrading , builder .GenericControlPlaneCRD , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
1799+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (controlPlaneUpgrading , builder .GenericControlPlaneCRD , unhealthyMachine , healthyMachine ).WithStatusSubresource (& clusterv1.Machine {}).Build ()
17951800 r := & Reconciler {
17961801 Client : fakeClient ,
17971802 PreflightChecks : sets.Set [clusterv1.MachineSetPreflightCheck ]{}.Insert (clusterv1 .MachineSetPreflightCheckAll ),
@@ -1934,7 +1939,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
19341939 }
19351940
19361941 machines := []* clusterv1.Machine {unhealthyMachine , healthyMachine }
1937- fakeClient := fake .NewClientBuilder ().WithObjects (
1942+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (
19381943 machineDeployment ,
19391944 machineSetOld ,
19401945 machineSetCurrent ,
@@ -2116,7 +2121,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
21162121 },
21172122 }
21182123
2119- fakeClient := fake .NewClientBuilder ().WithObjects (cluster , machineDeployment , healthyMachine ).
2124+ fakeClient := fake .NewClientBuilder ().WithScheme ( scheme ). WithObjects (cluster , machineDeployment , healthyMachine ).
21202125 WithStatusSubresource (& clusterv1.Machine {}, & clusterv1.MachineSet {}, & clusterv1.MachineDeployment {})
21212126 // Create the unhealthy machines.
21222127 for _ , machine := range unhealthyMachines {
0 commit comments