From 0fc6eb6e1885b5bd19f9c8782d131ad0611e79c4 Mon Sep 17 00:00:00 2001 From: enxebre Date: Wed, 28 Aug 2024 14:44:10 +0200 Subject: [PATCH] Do not return AvailabilitySet if failure domain is set in Machine It is not a valid config for Azure setting both AvailabilitySet and failure domain, this prevent this from happening for scenarios like externally manage infrastructure where AzureCluster.Status.FailureDomains might not be set but a consumer might still want to set a failure Domain for their pool of Machines --- azure/scope/machine.go | 3 +- azure/scope/machine_test.go | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/azure/scope/machine.go b/azure/scope/machine.go index e5e2aac09fb..278e0f6afb2 100644 --- a/azure/scope/machine.go +++ b/azure/scope/machine.go @@ -508,7 +508,8 @@ func (m *MachineScope) AvailabilitySetSpec() azure.ResourceSpecGetter { func (m *MachineScope) AvailabilitySet() (string, bool) { // AvailabilitySet service is not supported on EdgeZone currently. // AvailabilitySet cannot be used with Spot instances. - if !m.AvailabilitySetEnabled() || m.AzureMachine.Spec.SpotVMOptions != nil || m.ExtendedLocation() != nil { + if !m.AvailabilitySetEnabled() || m.AzureMachine.Spec.SpotVMOptions != nil || m.ExtendedLocation() != nil || + m.AzureMachine.Spec.FailureDomain != nil || m.Machine.Spec.FailureDomain != nil { return "", false } diff --git a/azure/scope/machine_test.go b/azure/scope/machine_test.go index b06b3001ffd..98c772c51f5 100644 --- a/azure/scope/machine_test.go +++ b/azure/scope/machine_test.go @@ -1411,6 +1411,65 @@ func TestMachineScope_AvailabilitySet(t *testing.T) { wantAvailabilitySetName: "", wantAvailabilitySetExistence: false, }, + { + name: "returns empty and false if machine has failureDomain set", + machineScope: MachineScope{ + ClusterScoper: &ClusterScope{ + Cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster", + }, + }, + AzureCluster: &infrav1.AzureCluster{ + Status: infrav1.AzureClusterStatus{}, + }, + }, + Machine: &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + clusterv1.MachineDeploymentNameLabel: "foo-machine-deployment", + }, + }, + Spec: clusterv1.MachineSpec{ + FailureDomain: ptr.To("1"), + }, + }, + AzureMachine: &infrav1.AzureMachine{ + Spec: infrav1.AzureMachineSpec{}, + }, + }, + wantAvailabilitySetName: "", + wantAvailabilitySetExistence: false, + }, + { + name: "returns empty and false if azureMachine has failureDomain set", + machineScope: MachineScope{ + ClusterScoper: &ClusterScope{ + Cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cluster", + }, + }, + AzureCluster: &infrav1.AzureCluster{ + Status: infrav1.AzureClusterStatus{}, + }, + }, + Machine: &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + clusterv1.MachineDeploymentNameLabel: "foo-machine-deployment", + }, + }, + }, + AzureMachine: &infrav1.AzureMachine{ + Spec: infrav1.AzureMachineSpec{ + FailureDomain: ptr.To("1"), + }, + }, + }, + wantAvailabilitySetName: "", + wantAvailabilitySetExistence: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {