@@ -570,6 +570,18 @@ var _ = Describe("Metal3Machine manager", func() {
570570 },
571571 },
572572 }
573+ hostWithFailureDomainLabel := bmov1alpha1.BareMetalHost {
574+ ObjectMeta : metav1.ObjectMeta {
575+ Name : "hostWithFailureDomainLabel" ,
576+ Namespace : namespaceName ,
577+ Labels : map [string ]string {FailureDomainLabelName : "my-fd-1" },
578+ },
579+ Status : bmov1alpha1.BareMetalHostStatus {
580+ Provisioning : bmov1alpha1.ProvisionStatus {
581+ State : bmov1alpha1 .StateAvailable ,
582+ },
583+ },
584+ }
573585 hostWithUnhealthyAnnotation := bmov1alpha1.BareMetalHost {
574586 ObjectMeta : metav1.ObjectMeta {
575587 Name : "hostWithUnhealthyAnnotation" ,
@@ -607,6 +619,19 @@ var _ = Describe("Metal3Machine manager", func() {
607619 },
608620 },
609621 }
622+ hostWithNodeReuseLabelSetToCPinFailureDomain := bmov1alpha1.BareMetalHost {
623+ ObjectMeta : metav1.ObjectMeta {
624+ Name : "hostWithNodeReuseLabelSetToCPinFailureDomain" ,
625+ Namespace : namespaceName ,
626+ Labels : map [string ]string {nodeReuseLabelName : "cp-test1" , FailureDomainLabelName : "my-fd-1" },
627+ },
628+ Spec : bmov1alpha1.BareMetalHostSpec {},
629+ Status : bmov1alpha1.BareMetalHostStatus {
630+ Provisioning : bmov1alpha1.ProvisionStatus {
631+ State : bmov1alpha1 .StateAvailable ,
632+ },
633+ },
634+ }
610635 hostWithNodeReuseLabelStateNone := bmov1alpha1.BareMetalHost {
611636 ObjectMeta : metav1.ObjectMeta {
612637 Name : "hostWithNodeReuseLabelStateNone" ,
@@ -622,13 +647,13 @@ var _ = Describe("Metal3Machine manager", func() {
622647 }
623648
624649 m3mconfig , infrastructureRef := newConfig ("" , map [string ]string {},
625- []infrav1.HostSelectorRequirement {},
650+ []infrav1.HostSelectorRequirement {}, "" ,
626651 )
627652 m3mconfig2 , infrastructureRef2 := newConfig ("" ,
628- map [string ]string {"key1" : "value1" }, []infrav1.HostSelectorRequirement {},
653+ map [string ]string {"key1" : "value1" }, []infrav1.HostSelectorRequirement {}, "" ,
629654 )
630655 m3mconfig3 , infrastructureRef3 := newConfig ("" ,
631- map [string ]string {"boguskey" : "value" }, []infrav1.HostSelectorRequirement {},
656+ map [string ]string {"boguskey" : "value" }, []infrav1.HostSelectorRequirement {}, "" ,
632657 )
633658 m3mconfig4 , infrastructureRef4 := newConfig ("" , map [string ]string {},
634659 []infrav1.HostSelectorRequirement {
@@ -638,6 +663,7 @@ var _ = Describe("Metal3Machine manager", func() {
638663 Values : []string {"abc" , "value1" , "123" },
639664 },
640665 },
666+ "" ,
641667 )
642668 m3mconfig5 , infrastructureRef5 := newConfig ("" , map [string ]string {},
643669 []infrav1.HostSelectorRequirement {
@@ -647,6 +673,10 @@ var _ = Describe("Metal3Machine manager", func() {
647673 Values : []string {"abc" , "value1" , "123" },
648674 },
649675 },
676+ "" ,
677+ )
678+ m3mconfig6 , infrastructureRef6 := newConfig ("" , map [string ]string {},
679+ []infrav1.HostSelectorRequirement {}, "my-fd-1" ,
650680 )
651681
652682 type testCaseChooseHost struct {
@@ -849,6 +879,68 @@ var _ = Describe("Metal3Machine manager", func() {
849879 M3Machine : m3mconfig5 ,
850880 ExpectedHostName : "" ,
851881 }),
882+ Entry ("Choose a host in Failure Domain" , testCaseChooseHost {
883+ Machine : newMachine (machineName , infrastructureRef6 ),
884+ Hosts : & bmov1alpha1.BareMetalHostList {Items : []bmov1alpha1.BareMetalHost {* availableHost , hostWithLabel , hostWithOtherConsRef , hostWithFailureDomainLabel }},
885+ M3Machine : m3mconfig6 ,
886+ ExpectedHostName : hostWithFailureDomainLabel .Name ,
887+ }),
888+ Entry ("Choose available host, when hosts in FailureDomain not available" , testCaseChooseHost {
889+ Machine : newMachine (machineName , infrastructureRef6 ),
890+ Hosts : & bmov1alpha1.BareMetalHostList {Items : []bmov1alpha1.BareMetalHost {* availableHost , hostWithOtherConsRef , hostWithNodeReuseLabelSetToCP }},
891+ M3Machine : m3mconfig6 ,
892+ ExpectedHostName : availableHost .Name ,
893+ }),
894+ Entry ("Choose a host in Failure Domain, when NodeReuse is set" , testCaseChooseHost {
895+ Machine : & clusterv1.Machine {
896+ ObjectMeta : metav1.ObjectMeta {
897+ Name : machineName ,
898+ Namespace : namespaceName ,
899+
900+ OwnerReferences : []metav1.OwnerReference {
901+ {
902+ APIVersion : "controlplane.cluster.x-k8s.io/v1beta2" ,
903+ Name : "test1" ,
904+ Kind : "KubeadmControlPlane" ,
905+ },
906+ },
907+ Labels : map [string ]string {
908+ clusterv1 .MachineControlPlaneLabel : "cluster.x-k8s.io/control-plane" ,
909+ },
910+ },
911+ Spec : clusterv1.MachineSpec {
912+ InfrastructureRef : * infrastructureRef ,
913+ },
914+ },
915+ Hosts : & bmov1alpha1.BareMetalHostList {Items : []bmov1alpha1.BareMetalHost {* availableHost , hostWithLabel , hostWithFailureDomainLabel , hostWithNodeReuseLabelSetToCPinFailureDomain }},
916+ M3Machine : m3mconfig6 ,
917+ ExpectedHostName : hostWithNodeReuseLabelSetToCPinFailureDomain .Name ,
918+ }),
919+ Entry ("Choose host is not in Failure Domain, when NodeReuse is set" , testCaseChooseHost {
920+ Machine : & clusterv1.Machine {
921+ ObjectMeta : metav1.ObjectMeta {
922+ Name : machineName ,
923+ Namespace : namespaceName ,
924+
925+ OwnerReferences : []metav1.OwnerReference {
926+ {
927+ APIVersion : "controlplane.cluster.x-k8s.io/v1beta2" ,
928+ Name : "test1" ,
929+ Kind : "KubeadmControlPlane" ,
930+ },
931+ },
932+ Labels : map [string ]string {
933+ clusterv1 .MachineControlPlaneLabel : "cluster.x-k8s.io/control-plane" ,
934+ },
935+ },
936+ Spec : clusterv1.MachineSpec {
937+ InfrastructureRef : * infrastructureRef ,
938+ },
939+ },
940+ Hosts : & bmov1alpha1.BareMetalHostList {Items : []bmov1alpha1.BareMetalHost {* availableHost , hostWithLabel , hostWithFailureDomainLabel , hostWithNodeReuseLabelSetToCP }},
941+ M3Machine : m3mconfig6 ,
942+ ExpectedHostName : hostWithNodeReuseLabelSetToCP .Name ,
943+ }),
852944 )
853945 })
854946
@@ -1085,7 +1177,7 @@ var _ = Describe("Metal3Machine manager", func() {
10851177 fakeClient := fake .NewClientBuilder ().WithScheme (setupSchemeMm ()).WithObjects (tc .Host ).Build ()
10861178
10871179 m3mconfig , infrastructureRef := newConfig (tc .UserDataNamespace ,
1088- map [string ]string {}, []infrav1.HostSelectorRequirement {},
1180+ map [string ]string {}, []infrav1.HostSelectorRequirement {}, "" ,
10891181 )
10901182 if tc .UseCustomDeploy != nil {
10911183 m3mconfig .Spec .Image = infrav1.Image {}
@@ -1205,7 +1297,7 @@ var _ = Describe("Metal3Machine manager", func() {
12051297 fakeClient := fake .NewClientBuilder ().WithScheme (setupSchemeMm ()).WithObjects (tc .Host ).Build ()
12061298
12071299 m3mconfig , infrastructureRef := newConfig (tc .UserDataNamespace ,
1208- map [string ]string {}, []infrav1.HostSelectorRequirement {},
1300+ map [string ]string {}, []infrav1.HostSelectorRequirement {}, "" ,
12091301 )
12101302 machine := newMachine (machineName , infrastructureRef )
12111303
@@ -4579,7 +4671,7 @@ func setupSchemeMm() *runtime.Scheme {
45794671}
45804672
45814673func newConfig (userDataNamespace string ,
4582- labels map [string ]string , reqs []infrav1.HostSelectorRequirement ,
4674+ labels map [string ]string , reqs []infrav1.HostSelectorRequirement , failureDomain string ,
45834675) (* infrav1.Metal3Machine , * clusterv1.ContractVersionedObjectReference ) {
45844676 config := infrav1.Metal3Machine {
45854677 ObjectMeta : metav1.ObjectMeta {
@@ -4599,6 +4691,7 @@ func newConfig(userDataNamespace string,
45994691 MatchLabels : labels ,
46004692 MatchExpressions : reqs ,
46014693 },
4694+ FailureDomain : failureDomain ,
46024695 },
46034696 Status : infrav1.Metal3MachineStatus {
46044697 UserData : & corev1.SecretReference {
0 commit comments