@@ -1395,6 +1395,11 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
13951395 g .Expect (ssa .Patch (ctx , env .Client , machineSetManagerName , bootstrapConfig )).To (Succeed ())
13961396 g .Expect (ssa .RemoveManagedFieldsForLabelsAndAnnotations (ctx , env .Client , env .GetAPIReader (), bootstrapConfig , machineSetManagerName )).To (Succeed ())
13971397
1398+ // Set ownerReferences of the Machines to the MachineSet to ensure deterministic field ownership by capi-machineset below.
1399+ // Note: There is code in the Machine controller that sets ownerRefs to the Cluster on standalone Machines.
1400+ inPlaceMutatingMachine .SetOwnerReferences ([]metav1.OwnerReference {* metav1 .NewControllerRef (ms , machineSetKind )})
1401+ deletingMachine .SetOwnerReferences ([]metav1.OwnerReference {* metav1 .NewControllerRef (ms , machineSetKind )})
1402+
13981403 // Create Machines (same as in syncReplicas)
13991404 g .Expect (ssa .Patch (ctx , env .Client , machineSetManagerName , inPlaceMutatingMachine )).To (Succeed ())
14001405 g .Expect (ssa .Patch (ctx , env .Client , machineSetManagerName , deletingMachine )).To (Succeed ())
@@ -1573,20 +1578,20 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
15731578 g .Eventually (func (g Gomega ) {
15741579 updatedDeletingMachine := deletingMachine .DeepCopy ()
15751580 g .Expect (env .GetAPIReader ().Get (ctx , client .ObjectKeyFromObject (updatedDeletingMachine ), updatedDeletingMachine )).To (Succeed ())
1576- statusManagedFields := managedFieldsMatching (updatedInPlaceMutatingMachine .ManagedFields , "manager" , metav1 .ManagedFieldsOperationUpdate , "status" )
1581+ statusManagedFields := managedFieldsMatching (updatedDeletingMachine .ManagedFields , "manager" , metav1 .ManagedFieldsOperationUpdate , "status" )
15771582 g .Expect (statusManagedFields ).To (HaveLen (1 ))
15781583 g .Expect (cleanupTime (updatedDeletingMachine .ManagedFields )).To (ConsistOf (toManagedFields ([]managedFieldEntry {{
15791584 // capi-machineset owns almost everything.
15801585 Manager : machineSetManagerName ,
15811586 Operation : metav1 .ManagedFieldsOperationApply ,
15821587 APIVersion : clusterv1 .GroupVersion .String (),
1583- FieldsV1 : "{\" f:metadata\" :{\" f:finalizers\" :{\" v:\\ \" testing-finalizer\\ \" \" :{}}} ,\" f:spec\" :{\" f:bootstrap\" :{\" f:dataSecretName\" :{}},\" f:clusterName\" :{},\" f:infrastructureRef\" :{\" f:apiGroup\" :{},\" f:kind\" :{},\" f:name\" :{}}}}" ,
1588+ FieldsV1 : fmt . Sprintf ( "{\" f:metadata\" :{\" f:finalizers\" :{\" v:\\ \" testing-finalizer\\ \" \" :{}}, \" f:ownerReferences \" :{ \" k:{ \\ \" uid \\ \" : \\ \" %s \\ \" } \" :{}}} ,\" f:spec\" :{\" f:bootstrap\" :{\" f:dataSecretName\" :{}},\" f:clusterName\" :{},\" f:infrastructureRef\" :{\" f:apiGroup\" :{},\" f:kind\" :{},\" f:name\" :{}}}}" , ms . UID ) ,
15841589 }, {
15851590 // manager owns the fields that are propagated in-place for deleting Machines in syncMachines via patchHelper.
15861591 Manager : "manager" ,
15871592 Operation : metav1 .ManagedFieldsOperationUpdate ,
15881593 APIVersion : clusterv1 .GroupVersion .String (),
1589- FieldsV1 : fmt . Sprintf ( "{\" f:metadata \" :{ \" f:ownerReferences \" :{ \" . \" :{}, \" k:{ \\ \" uid \\ \" : \\ \" %s \\ \" } \" :{}}}, \" f: spec\" :{\" f:deletion\" :{\" f:nodeDrainTimeoutSeconds\" :{},\" f:nodeVolumeDetachTimeoutSeconds\" :{}},\" f:minReadySeconds\" :{},\" f:readinessGates\" :{\" .\" :{},\" k:{\\ \" conditionType\\ \" :\\ \" foo\\ \" }\" :{\" .\" :{},\" f:conditionType\" :{}}}}}" , testCluster . UID ) ,
1594+ FieldsV1 : "{\" f:spec\" :{\" f:deletion\" :{\" f:nodeDrainTimeoutSeconds\" :{},\" f:nodeVolumeDetachTimeoutSeconds\" :{}},\" f:minReadySeconds\" :{},\" f:readinessGates\" :{\" .\" :{},\" k:{\\ \" conditionType\\ \" :\\ \" foo\\ \" }\" :{\" .\" :{},\" f:conditionType\" :{}}}}}" ,
15901595 }, {
15911596 // manager owns status.
15921597 Manager : "manager" ,
0 commit comments