@@ -269,7 +269,7 @@ func (f *FakeCluster) Objs() []client.Object {
269269 if f .controlPlane == nil && i == 0 {
270270 generateCerts = true
271271 }
272- objs = append (objs , machine .Objs (cluster , generateCerts , nil , nil )... )
272+ objs = append (objs , machine .Objs (cluster , generateCerts , nil , nil , nil )... )
273273 }
274274
275275 // Ensure all the objects gets UID.
@@ -403,7 +403,7 @@ func (f *FakeControlPlane) Objs(cluster *clusterv1.Cluster) []client.Object {
403403
404404 // Adds the objects for the machines controlled by the controlPlane
405405 for _ , machine := range f .machines {
406- objs = append (objs , machine .Objs (cluster , false , nil , controlPlane )... )
406+ objs = append (objs , machine .Objs (cluster , false , nil , nil , controlPlane )... )
407407 }
408408
409409 return objs
@@ -412,6 +412,7 @@ func (f *FakeControlPlane) Objs(cluster *clusterv1.Cluster) []client.Object {
412412type FakeMachinePool struct {
413413 name string
414414 bootstrapConfig * clusterv1.Bootstrap
415+ machines []* FakeMachine
415416}
416417
417418// NewFakeMachinePool return a FakeMachinePool that can generate a MachinePool object, all its own ancillary objects:
@@ -428,6 +429,11 @@ func (f *FakeMachinePool) WithStaticBootstrapConfig() *FakeMachinePool {
428429 return f
429430}
430431
432+ func (f * FakeMachinePool ) WithMachines (fakeMachine ... * FakeMachine ) * FakeMachinePool {
433+ f .machines = append (f .machines , fakeMachine ... )
434+ return f
435+ }
436+
431437func (f * FakeMachinePool ) Objs (cluster * clusterv1.Cluster ) []client.Object {
432438 machinePoolInfrastructure := & fakeinfrastructure.GenericInfrastructureMachineTemplate {
433439 TypeMeta : metav1.TypeMeta {
@@ -523,6 +529,10 @@ func (f *FakeMachinePool) Objs(cluster *clusterv1.Cluster) []client.Object {
523529 objs = append (objs , machinePoolBootstrap )
524530 }
525531
532+ for _ , machine := range f .machines {
533+ objs = append (objs , machine .Objs (cluster , false , nil , machinePool , nil )... )
534+ }
535+
526536 return objs
527537}
528538
@@ -847,7 +857,7 @@ func (f *FakeMachineSet) Objs(cluster *clusterv1.Cluster, machineDeployment *clu
847857
848858 // Adds the objects for the machines controlled by the machineSet
849859 for _ , machine := range f .machines {
850- objs = append (objs , machine .Objs (cluster , false , machineSet , nil )... )
860+ objs = append (objs , machine .Objs (cluster , false , machineSet , nil , nil )... )
851861 }
852862
853863 return objs
@@ -873,7 +883,7 @@ func (f *FakeMachine) WithStaticBootstrapConfig() *FakeMachine {
873883 return f
874884}
875885
876- func (f * FakeMachine ) Objs (cluster * clusterv1.Cluster , generateCerts bool , machineSet * clusterv1.MachineSet , controlPlane * fakecontrolplane.GenericControlPlane ) []client.Object {
886+ func (f * FakeMachine ) Objs (cluster * clusterv1.Cluster , generateCerts bool , machineSet * clusterv1.MachineSet , machinePool * expv1. MachinePool , controlPlane * fakecontrolplane.GenericControlPlane ) []client.Object {
877887 machineInfrastructure := & fakeinfrastructure.GenericInfrastructureMachine {
878888 TypeMeta : metav1.TypeMeta {
879889 APIVersion : fakeinfrastructure .GroupVersion .String (),
@@ -955,8 +965,6 @@ func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machi
955965 },
956966 }
957967
958- machine .Spec .Bootstrap = * bootstrapConfig
959-
960968 // Ensure the machine gets a UID to be used by dependant objects for creating OwnerReferences.
961969 setUID (machine )
962970
@@ -971,6 +979,11 @@ func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machi
971979 machine .SetOwnerReferences ([]metav1.OwnerReference {* metav1 .NewControllerRef (controlPlane , controlPlane .GroupVersionKind ())})
972980 // Sets the MachineControlPlane Label
973981 machine .Labels [clusterv1 .MachineControlPlaneLabel ] = ""
982+ case machinePool != nil :
983+ // If this machine belong to a machinePool, it is controlled by it / ownership set by the machinePool controller -- ** NOT RECONCILED **
984+ machine .SetOwnerReferences ([]metav1.OwnerReference {* metav1 .NewControllerRef (machinePool , machinePool .GroupVersionKind ())})
985+ // Sets the MachinePoolNameLabel
986+ machine .Labels [clusterv1 .MachinePoolNameLabel ] = machinePool .Name
974987 default :
975988 // If this machine does not belong to a machineSet or to a control plane, it is owned by the cluster / ownership set by the machine controller -- RECONCILED
976989 machine .SetOwnerReferences ([]metav1.OwnerReference {{
@@ -1017,20 +1030,23 @@ func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machi
10171030 machineInfrastructure ,
10181031 }
10191032
1020- if machine .Spec .Bootstrap .ConfigRef != nil {
1021- machineBootstrap .SetOwnerReferences ([]metav1.OwnerReference {
1022- {
1023- APIVersion : machine .APIVersion ,
1024- Kind : machine .Kind ,
1025- Name : machine .Name ,
1026- UID : machine .UID ,
1027- },
1028- })
1029- machineBootstrap .SetLabels (map [string ]string {
1030- clusterv1 .ClusterNameLabel : machine .Spec .ClusterName ,
1031- })
1033+ if machinePool == nil {
1034+ machine .Spec .Bootstrap = * bootstrapConfig
1035+ if machine .Spec .Bootstrap .ConfigRef != nil {
1036+ machineBootstrap .SetOwnerReferences ([]metav1.OwnerReference {
1037+ {
1038+ APIVersion : machine .APIVersion ,
1039+ Kind : machine .Kind ,
1040+ Name : machine .Name ,
1041+ UID : machine .UID ,
1042+ },
1043+ })
1044+ machineBootstrap .SetLabels (map [string ]string {
1045+ clusterv1 .ClusterNameLabel : machine .Spec .ClusterName ,
1046+ })
10321047
1033- objs = append (objs , bootstrapDataSecret , machineBootstrap )
1048+ objs = append (objs , bootstrapDataSecret , machineBootstrap )
1049+ }
10341050 }
10351051
10361052 objs = append (objs , additionalObjs ... )
0 commit comments