@@ -269,7 +269,7 @@ func (f *FakeCluster) Objs() []client.Object {
269
269
if f .controlPlane == nil && i == 0 {
270
270
generateCerts = true
271
271
}
272
- objs = append (objs , machine .Objs (cluster , generateCerts , nil , nil )... )
272
+ objs = append (objs , machine .Objs (cluster , generateCerts , nil , nil , nil )... )
273
273
}
274
274
275
275
// Ensure all the objects gets UID.
@@ -403,7 +403,7 @@ func (f *FakeControlPlane) Objs(cluster *clusterv1.Cluster) []client.Object {
403
403
404
404
// Adds the objects for the machines controlled by the controlPlane
405
405
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 )... )
407
407
}
408
408
409
409
return objs
@@ -412,6 +412,7 @@ func (f *FakeControlPlane) Objs(cluster *clusterv1.Cluster) []client.Object {
412
412
type FakeMachinePool struct {
413
413
name string
414
414
bootstrapConfig * clusterv1.Bootstrap
415
+ machines []* FakeMachine
415
416
}
416
417
417
418
// NewFakeMachinePool return a FakeMachinePool that can generate a MachinePool object, all its own ancillary objects:
@@ -428,6 +429,11 @@ func (f *FakeMachinePool) WithStaticBootstrapConfig() *FakeMachinePool {
428
429
return f
429
430
}
430
431
432
+ func (f * FakeMachinePool ) WithMachines (fakeMachine ... * FakeMachine ) * FakeMachinePool {
433
+ f .machines = append (f .machines , fakeMachine ... )
434
+ return f
435
+ }
436
+
431
437
func (f * FakeMachinePool ) Objs (cluster * clusterv1.Cluster ) []client.Object {
432
438
machinePoolInfrastructure := & fakeinfrastructure.GenericInfrastructureMachineTemplate {
433
439
TypeMeta : metav1.TypeMeta {
@@ -523,6 +529,10 @@ func (f *FakeMachinePool) Objs(cluster *clusterv1.Cluster) []client.Object {
523
529
objs = append (objs , machinePoolBootstrap )
524
530
}
525
531
532
+ for _ , machine := range f .machines {
533
+ objs = append (objs , machine .Objs (cluster , false , nil , machinePool , nil )... )
534
+ }
535
+
526
536
return objs
527
537
}
528
538
@@ -847,7 +857,7 @@ func (f *FakeMachineSet) Objs(cluster *clusterv1.Cluster, machineDeployment *clu
847
857
848
858
// Adds the objects for the machines controlled by the machineSet
849
859
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 )... )
851
861
}
852
862
853
863
return objs
@@ -873,7 +883,7 @@ func (f *FakeMachine) WithStaticBootstrapConfig() *FakeMachine {
873
883
return f
874
884
}
875
885
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 {
877
887
machineInfrastructure := & fakeinfrastructure.GenericInfrastructureMachine {
878
888
TypeMeta : metav1.TypeMeta {
879
889
APIVersion : fakeinfrastructure .GroupVersion .String (),
@@ -955,8 +965,6 @@ func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machi
955
965
},
956
966
}
957
967
958
- machine .Spec .Bootstrap = * bootstrapConfig
959
-
960
968
// Ensure the machine gets a UID to be used by dependant objects for creating OwnerReferences.
961
969
setUID (machine )
962
970
@@ -971,6 +979,11 @@ func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machi
971
979
machine .SetOwnerReferences ([]metav1.OwnerReference {* metav1 .NewControllerRef (controlPlane , controlPlane .GroupVersionKind ())})
972
980
// Sets the MachineControlPlane Label
973
981
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
974
987
default :
975
988
// 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
976
989
machine .SetOwnerReferences ([]metav1.OwnerReference {{
@@ -1017,20 +1030,23 @@ func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machi
1017
1030
machineInfrastructure ,
1018
1031
}
1019
1032
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
+ })
1032
1047
1033
- objs = append (objs , bootstrapDataSecret , machineBootstrap )
1048
+ objs = append (objs , bootstrapDataSecret , machineBootstrap )
1049
+ }
1034
1050
}
1035
1051
1036
1052
objs = append (objs , additionalObjs ... )
0 commit comments