Skip to content

Commit

Permalink
Merge pull request #5098 from enxebre/AvailabilitySet-fix
Browse files Browse the repository at this point in the history
Do not return AvailabilitySet if failure domain is set in Machine
  • Loading branch information
k8s-ci-robot authored Sep 5, 2024
2 parents 420c741 + 0fc6eb6 commit 3bf7e50
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
59 changes: 59 additions & 0 deletions azure/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3bf7e50

Please sign in to comment.