Skip to content

Commit

Permalink
OCM-5576 | fix: Edit autoscaling max replicas of nodepool force to se…
Browse files Browse the repository at this point in the history
…t min replicas

Signed-off-by: Maggie Chen <magchen@redhat.com>

move changed

Signed-off-by: Maggie Chen <magchen@redhat.com>

refactor

Signed-off-by: Maggie Chen <magchen@redhat.com>

refactor

Signed-off-by: Maggie Chen <magchen@redhat.com>
  • Loading branch information
chenz4027 committed May 7, 2024
1 parent da3615e commit a7a66af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cmd/edit/machinepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,24 @@ func getNodePoolReplicas(cmd *cobra.Command,
}

func editAutoscaling(nodePool *cmv1.NodePool, minReplicas int, maxReplicas int) *cmv1.NodePoolAutoscalingBuilder {
asBuilder := cmv1.NewNodePoolAutoscaling()
changed := false
existingMinReplica := nodePool.Autoscaling().MinReplica()
existingMaxReplica := nodePool.Autoscaling().MaxReplica()

if nodePool.Autoscaling().MinReplica() != minReplicas && minReplicas >= 1 {
asBuilder = asBuilder.MinReplica(minReplicas)
changed = true
min := existingMinReplica
max := existingMaxReplica

if minReplicas != 0 {
min = minReplicas
}
if nodePool.Autoscaling().MaxReplica() != maxReplicas && maxReplicas >= 1 {
asBuilder = asBuilder.MaxReplica(maxReplicas)
changed = true
if maxReplicas != 0 {
max = maxReplicas
}

if changed {
return asBuilder
if existingMinReplica != minReplicas || existingMaxReplica != maxReplicas {
if min >= 1 && max >= 1 {
return cmv1.NewNodePoolAutoscaling().MinReplica(min).MaxReplica(max)
}
}

return nil
}
20 changes: 20 additions & 0 deletions cmd/edit/machinepool/nodepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,25 @@ var _ = Describe("Nodepool", func() {
asBuilder := cmv1.NewNodePoolAutoscaling().MaxReplica(3).MinReplica(2)
Expect(builder).To(Equal(asBuilder))
})

It("editAutoscaling should equal the exepcted output with no min replica value", func() {
nodepool, err := cmv1.NewNodePool().
Autoscaling(cmv1.NewNodePoolAutoscaling().MaxReplica(2).MinReplica(1)).
Build()
Expect(err).ToNot(HaveOccurred())
builder := editAutoscaling(nodepool, 0, 3)
asBuilder := cmv1.NewNodePoolAutoscaling().MaxReplica(3).MinReplica(1)
Expect(builder).To(Equal(asBuilder))
})

It("editAutoscaling should equal the exepcted output with no max replica value", func() {
nodepool, err := cmv1.NewNodePool().
Autoscaling(cmv1.NewNodePoolAutoscaling().MaxReplica(4).MinReplica(1)).
Build()
Expect(err).ToNot(HaveOccurred())
builder := editAutoscaling(nodepool, 2, 0)
asBuilder := cmv1.NewNodePoolAutoscaling().MaxReplica(4).MinReplica(2)
Expect(builder).To(Equal(asBuilder))
})
})
})

0 comments on commit a7a66af

Please sign in to comment.