Skip to content

Commit

Permalink
Merge pull request #104 from RadekManak/cherry-pick-98-to-release-4.13
Browse files Browse the repository at this point in the history
[release-4.13] OCPBUGS-29906: Don't create availability set when using spot instances
  • Loading branch information
openshift-merge-bot[bot] committed Mar 12, 2024
2 parents 5923f3f + 0fa855e commit 62f6e0f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pkg/cloud/azure/actuators/machine/reconciler.go
Expand Up @@ -788,6 +788,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
25 changes: 18 additions & 7 deletions pkg/termination/termination_test.go
Expand Up @@ -124,6 +124,8 @@ var _ = Describe("Handler Suite", func() {
var counter int32

BeforeEach(func() {
counter = 0

// Ensure the polling logic is excercised in tests
httpHandler = newMockHTTPHandler(func(rw http.ResponseWriter, req *http.Request) {
if atomic.LoadInt32(&counter) == 4 {
Expand All @@ -135,15 +137,15 @@ var _ = Describe("Handler Suite", func() {
})
})

JustBeforeEach(func() {
// Ensure the polling logic is excercised in tests
for atomic.LoadInt32(&counter) < 4 {
continue
}
})

Context("and the handler is stopped", func() {
JustBeforeEach(func() {
// Ensure the polling logic is tested as well
for atomic.LoadInt32(&counter) < 4 {
// use 50ms since polling is set to 100ms
time.Sleep(50 * time.Millisecond)
continue
}

close(stop)
})

Expand All @@ -157,6 +159,15 @@ var _ = Describe("Handler Suite", func() {
})

Context("and the instance termination notice is fulfilled", func() {
JustBeforeEach(func() {
// Ensure the polling logic is tested as well
for atomic.LoadInt32(&counter) < 4 {
// use 50ms since polling is set to 100ms
time.Sleep(50 * time.Millisecond)
continue
}
})

It("should mark the node for deletion", func() {
Eventually(nodeMarkedForDeletion(testNode.Name)).Should(BeTrue())
})
Expand Down

0 comments on commit 62f6e0f

Please sign in to comment.