Skip to content

Commit

Permalink
Don't create availability set when using spot instances
Browse files Browse the repository at this point in the history
  • Loading branch information
RadekManak committed Jan 8, 2024
1 parent ee267f0 commit 503e6e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/cloud/azure/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,11 @@ func (s *Reconciler) getOrCreateAvailabilitySet() (string, error) {
return "", nil
}

if s.scope.MachineConfig.SpotVMOptions != nil {
klog.V(4).Infof("MachineSet %s uses spot instances, skipping availability set creation", s.scope.Machine.Name)
return "", nil
}

klog.V(4).Infof("No availability zones were found for %s, an availability set will be created", s.scope.Machine.Name)

if err := s.availabilitySetsSvc.CreateOrUpdate(context.Background(), &availabilitysets.Spec{
Expand Down
18 changes: 18 additions & 0 deletions pkg/cloud/azure/actuators/machine/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func TestCreateAvailabilitySet(t *testing.T) {
availabilitySetsSvc func() *mock_azure.MockService
availabilityZonesSvc func() *mock_azure.MockService
inputASName string
spotVMOptions *machinev1.SpotVMOptions
}{
{
name: "Error when availability zones client fails",
Expand Down Expand Up @@ -414,6 +415,22 @@ func TestCreateAvailabilitySet(t *testing.T) {
return availabilitySetsSvc
},
},
{
name: "Skip availability set creation when using Spot instances",
availabilityZonesSvc: func() *mock_azure.MockService {
availabilityZonesSvc := mock_azure.NewMockService(mockCtrl)
availabilityZonesSvc.EXPECT().Get(gomock.Any(), gomock.Any()).Return([]string{}, nil).Times(1)
return availabilityZonesSvc
},
availabilitySetsSvc: func() *mock_azure.MockService {
availabilitySetsSvc := mock_azure.NewMockService(mockCtrl)
availabilitySetsSvc.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any()).Return(nil).Times(0)
return availabilitySetsSvc
},
spotVMOptions: &machinev1.SpotVMOptions{
MaxPrice: resource.NewQuantity(-1, resource.DecimalSI),
},
},
{
name: "Skip availability set creation when name was specified in provider spec",
labels: map[string]string{},
Expand Down Expand Up @@ -486,6 +503,7 @@ func TestCreateAvailabilitySet(t *testing.T) {
MachineConfig: &machinev1.AzureMachineProviderSpec{
VMSize: "Standard_D2_v2",
AvailabilitySet: tc.inputASName,
SpotVMOptions: tc.spotVMOptions,
},
},
}
Expand Down

0 comments on commit 503e6e5

Please sign in to comment.