Skip to content

Commit

Permalink
OCM-7937 | fix: allow 0 min replicas for classic cluster autoscaling mp
Browse files Browse the repository at this point in the history
  • Loading branch information
davidleerh committed May 10, 2024
1 parent 26ce7d6 commit dc61e69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/edit/machinepool/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,20 @@ func editMachinePoolAutoscaling(machinePool *cmv1.MachinePool,
asBuilder := cmv1.NewMachinePoolAutoscaling()
changed := false

if machinePool.Autoscaling().MinReplicas() != minReplicas && minReplicas >= 1 {
asBuilder = asBuilder.MinReplicas(minReplicas)
newMin := machinePool.Autoscaling().MinReplicas()
newMax := machinePool.Autoscaling().MaxReplicas()

if machinePool.Autoscaling().MinReplicas() != minReplicas && minReplicas >= 0 {
newMin = minReplicas
changed = true
}
if machinePool.Autoscaling().MaxReplicas() != maxReplicas && maxReplicas >= 1 {
asBuilder = asBuilder.MaxReplicas(maxReplicas)
if machinePool.Autoscaling().MaxReplicas() != maxReplicas && maxReplicas >= 0 {
newMax = maxReplicas
changed = true
}

if changed {
asBuilder = asBuilder.MinReplicas(newMin).MaxReplicas(newMax)
return asBuilder
}
return nil
Expand Down
20 changes: 20 additions & 0 deletions cmd/edit/machinepool/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ var _ = Describe("Machinepool", func() {
asBuilder := cmv1.NewMachinePoolAutoscaling().MaxReplicas(3).MinReplicas(2)
Expect(builder).To(Equal(asBuilder))
})

It("editMachinePoolAutoscaling should allow 0 min replicas", func() {
machinePool, err := cmv1.NewMachinePool().
Autoscaling(cmv1.NewMachinePoolAutoscaling().MaxReplicas(2).MinReplicas(1)).
Build()
Expect(err).ToNot(HaveOccurred())
builder := editMachinePoolAutoscaling(machinePool, 0, 2)
asBuilder := cmv1.NewMachinePoolAutoscaling().MaxReplicas(2).MinReplicas(0)
Expect(builder).To(Equal(asBuilder))
})

It("editMachinePoolAutoscaling should allow 0 min and 0 max replicas", func() {
machinePool, err := cmv1.NewMachinePool().
Autoscaling(cmv1.NewMachinePoolAutoscaling().MaxReplicas(2).MinReplicas(1)).
Build()
Expect(err).ToNot(HaveOccurred())
builder := editMachinePoolAutoscaling(machinePool, 0, 0)
asBuilder := cmv1.NewMachinePoolAutoscaling().MaxReplicas(0).MinReplicas(0)
Expect(builder).To(Equal(asBuilder))
})
})

Context("isMultiAZMachinePool", func() {
Expand Down

0 comments on commit dc61e69

Please sign in to comment.