Skip to content

Commit 0fc6eb6

Browse files
committed
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
1 parent cc3e8e9 commit 0fc6eb6

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

azure/scope/machine.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ func (m *MachineScope) AvailabilitySetSpec() azure.ResourceSpecGetter {
508508
func (m *MachineScope) AvailabilitySet() (string, bool) {
509509
// AvailabilitySet service is not supported on EdgeZone currently.
510510
// AvailabilitySet cannot be used with Spot instances.
511-
if !m.AvailabilitySetEnabled() || m.AzureMachine.Spec.SpotVMOptions != nil || m.ExtendedLocation() != nil {
511+
if !m.AvailabilitySetEnabled() || m.AzureMachine.Spec.SpotVMOptions != nil || m.ExtendedLocation() != nil ||
512+
m.AzureMachine.Spec.FailureDomain != nil || m.Machine.Spec.FailureDomain != nil {
512513
return "", false
513514
}
514515

azure/scope/machine_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,65 @@ func TestMachineScope_AvailabilitySet(t *testing.T) {
14111411
wantAvailabilitySetName: "",
14121412
wantAvailabilitySetExistence: false,
14131413
},
1414+
{
1415+
name: "returns empty and false if machine has failureDomain set",
1416+
machineScope: MachineScope{
1417+
ClusterScoper: &ClusterScope{
1418+
Cluster: &clusterv1.Cluster{
1419+
ObjectMeta: metav1.ObjectMeta{
1420+
Name: "cluster",
1421+
},
1422+
},
1423+
AzureCluster: &infrav1.AzureCluster{
1424+
Status: infrav1.AzureClusterStatus{},
1425+
},
1426+
},
1427+
Machine: &clusterv1.Machine{
1428+
ObjectMeta: metav1.ObjectMeta{
1429+
Labels: map[string]string{
1430+
clusterv1.MachineDeploymentNameLabel: "foo-machine-deployment",
1431+
},
1432+
},
1433+
Spec: clusterv1.MachineSpec{
1434+
FailureDomain: ptr.To("1"),
1435+
},
1436+
},
1437+
AzureMachine: &infrav1.AzureMachine{
1438+
Spec: infrav1.AzureMachineSpec{},
1439+
},
1440+
},
1441+
wantAvailabilitySetName: "",
1442+
wantAvailabilitySetExistence: false,
1443+
},
1444+
{
1445+
name: "returns empty and false if azureMachine has failureDomain set",
1446+
machineScope: MachineScope{
1447+
ClusterScoper: &ClusterScope{
1448+
Cluster: &clusterv1.Cluster{
1449+
ObjectMeta: metav1.ObjectMeta{
1450+
Name: "cluster",
1451+
},
1452+
},
1453+
AzureCluster: &infrav1.AzureCluster{
1454+
Status: infrav1.AzureClusterStatus{},
1455+
},
1456+
},
1457+
Machine: &clusterv1.Machine{
1458+
ObjectMeta: metav1.ObjectMeta{
1459+
Labels: map[string]string{
1460+
clusterv1.MachineDeploymentNameLabel: "foo-machine-deployment",
1461+
},
1462+
},
1463+
},
1464+
AzureMachine: &infrav1.AzureMachine{
1465+
Spec: infrav1.AzureMachineSpec{
1466+
FailureDomain: ptr.To("1"),
1467+
},
1468+
},
1469+
},
1470+
wantAvailabilitySetName: "",
1471+
wantAvailabilitySetExistence: false,
1472+
},
14141473
}
14151474
for _, tt := range tests {
14161475
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)