Skip to content

Commit

Permalink
Merge pull request #95 from openshift-cherrypick-robot/cherry-pick-91…
Browse files Browse the repository at this point in the history
…-to-release-4.15

[release-4.15] OCPBUGS-29007: Don't create availability set when using spot instances
  • Loading branch information
openshift-merge-bot[bot] committed Feb 7, 2024
2 parents 7f41c22 + d4c6d35 commit 34e8ac0
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
Expand Up @@ -800,6 +800,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
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 34e8ac0

Please sign in to comment.