Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cloud/services/scalesets/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type (
PublicLoadBalancerName string
AdditionalTags infrav1.Tags
AcceleratedNetworking *bool
FailureDomains []string
}
)

Expand Down Expand Up @@ -173,6 +174,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
},
},
},
Zones: to.StringSlicePtr(vmssSpec.FailureDomains),
}

err = s.Client.CreateOrUpdate(
Expand Down
8 changes: 6 additions & 2 deletions cloud/services/scalesets/vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ func TestService_Reconcile(t *testing.T) {
Image: &infrav1.Image{
ID: to.StringPtr("image"),
},
CustomData: "customData",
CustomData: "customData",
FailureDomains: []string{"1"},
}
},
Setup: func(ctx context.Context, g *gomega.GomegaWithT, svc *Service, scope *scope.ClusterScope, mpScope *scope.MachinePoolScope, spec *Spec) {
Expand Down Expand Up @@ -350,6 +351,7 @@ func TestService_Reconcile(t *testing.T) {
},
},
},
Zones: to.StringSlicePtr(spec.FailureDomains),
}

skusMock.EXPECT().HasAcceleratedNetworking(gomock.Any(), gomock.Any()).Return(false, nil)
Expand Down Expand Up @@ -384,7 +386,8 @@ func TestService_Reconcile(t *testing.T) {
Image: &infrav1.Image{
ID: to.StringPtr("image"),
},
CustomData: "customData",
CustomData: "customData",
FailureDomains: []string{"1"},
}
},
Setup: func(ctx context.Context, g *gomega.GomegaWithT, svc *Service, scope *scope.ClusterScope, mpScope *scope.MachinePoolScope, spec *Spec) {
Expand Down Expand Up @@ -461,6 +464,7 @@ func TestService_Reconcile(t *testing.T) {
},
},
},
Zones: to.StringSlicePtr(spec.FailureDomains),
}

skusMock.EXPECT().HasAcceleratedNetworking(gomock.Any(), gomock.Any()).Return(true, nil)
Expand Down
30 changes: 30 additions & 0 deletions exp/controllers/azuremachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ func (s *azureMachinePoolService) CreateOrUpdate() (*infrav1exp.VMSS, error) {
return nil, errors.Wrap(err, "failed to retrieve bootstrap data")
}

failureDomains, err := getFailureDomains(s)
if err != nil {
return nil, errors.Wrap(err, "failed to retrieve failure domains")
}

vmssSpec := &scalesets.Spec{
Name: s.machinePoolScope.Name(),
ResourceGroup: s.clusterScope.ResourceGroup(),
Expand All @@ -505,6 +510,7 @@ func (s *azureMachinePoolService) CreateOrUpdate() (*infrav1exp.VMSS, error) {
SubnetID: s.clusterScope.AzureCluster.Spec.NetworkSpec.Subnets[0].ID,
PublicLoadBalancerName: s.clusterScope.Name(),
AcceleratedNetworking: ampSpec.Template.AcceleratedNetworking,
FailureDomains: failureDomains,
}

err = s.virtualMachinesScaleSetSvc.Reconcile(context.TODO(), vmssSpec)
Expand Down Expand Up @@ -539,6 +545,30 @@ func (s *azureMachinePoolService) CreateOrUpdate() (*infrav1exp.VMSS, error) {
return vmss, nil
}

func getFailureDomains(s *azureMachinePoolService) ([]string, error) {
if s.machinePoolScope.MachinePool.Spec.FailureDomains == nil {
return getFailureDomainsIDs(s.clusterScope.AzureCluster.Status.FailureDomains), nil
}

selectedFDsIDs := getFailureDomainsIDs(s.machinePoolScope.MachinePool.Spec.FailureDomains)
for _, fdName := range selectedFDsIDs {
if _, exists := s.clusterScope.AzureCluster.Status.FailureDomains[fdName]; !exists {
return []string{}, errors.Errorf("Selected FailureDomain %#q is not available on this location", fdName)
}
}

return selectedFDsIDs, nil
}

func getFailureDomainsIDs(selectedFailureDomains capiv1.FailureDomains) []string {
failureDomains := make([]string, 0, len(selectedFailureDomains))
for fdName := range selectedFailureDomains {
failureDomains = append(failureDomains, fdName)
}

return failureDomains
}

// Delete reconciles all the services in pre determined order
func (s *azureMachinePoolService) Delete() error {
vmssSpec := &scalesets.Spec{
Expand Down