Skip to content

Commit 503e6e5

Browse files
committed
Don't create availability set when using spot instances
1 parent ee267f0 commit 503e6e5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pkg/cloud/azure/actuators/machine/reconciler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,11 @@ func (s *Reconciler) getOrCreateAvailabilitySet() (string, error) {
791791
return "", nil
792792
}
793793

794+
if s.scope.MachineConfig.SpotVMOptions != nil {
795+
klog.V(4).Infof("MachineSet %s uses spot instances, skipping availability set creation", s.scope.Machine.Name)
796+
return "", nil
797+
}
798+
794799
klog.V(4).Infof("No availability zones were found for %s, an availability set will be created", s.scope.Machine.Name)
795800

796801
if err := s.availabilitySetsSvc.CreateOrUpdate(context.Background(), &availabilitysets.Spec{

pkg/cloud/azure/actuators/machine/reconciler_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func TestCreateAvailabilitySet(t *testing.T) {
333333
availabilitySetsSvc func() *mock_azure.MockService
334334
availabilityZonesSvc func() *mock_azure.MockService
335335
inputASName string
336+
spotVMOptions *machinev1.SpotVMOptions
336337
}{
337338
{
338339
name: "Error when availability zones client fails",
@@ -414,6 +415,22 @@ func TestCreateAvailabilitySet(t *testing.T) {
414415
return availabilitySetsSvc
415416
},
416417
},
418+
{
419+
name: "Skip availability set creation when using Spot instances",
420+
availabilityZonesSvc: func() *mock_azure.MockService {
421+
availabilityZonesSvc := mock_azure.NewMockService(mockCtrl)
422+
availabilityZonesSvc.EXPECT().Get(gomock.Any(), gomock.Any()).Return([]string{}, nil).Times(1)
423+
return availabilityZonesSvc
424+
},
425+
availabilitySetsSvc: func() *mock_azure.MockService {
426+
availabilitySetsSvc := mock_azure.NewMockService(mockCtrl)
427+
availabilitySetsSvc.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any()).Return(nil).Times(0)
428+
return availabilitySetsSvc
429+
},
430+
spotVMOptions: &machinev1.SpotVMOptions{
431+
MaxPrice: resource.NewQuantity(-1, resource.DecimalSI),
432+
},
433+
},
417434
{
418435
name: "Skip availability set creation when name was specified in provider spec",
419436
labels: map[string]string{},
@@ -486,6 +503,7 @@ func TestCreateAvailabilitySet(t *testing.T) {
486503
MachineConfig: &machinev1.AzureMachineProviderSpec{
487504
VMSize: "Standard_D2_v2",
488505
AvailabilitySet: tc.inputASName,
506+
SpotVMOptions: tc.spotVMOptions,
489507
},
490508
},
491509
}

0 commit comments

Comments
 (0)