Skip to content

Commit

Permalink
OCM-7990 | fix: allow min_replicas 0 with edit machinepools
Browse files Browse the repository at this point in the history
  • Loading branch information
davidleerh authored and openshift-cherrypick-robot committed May 13, 2024
1 parent f6371d7 commit 967bfb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
20 changes: 12 additions & 8 deletions cmd/edit/machinepool/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,21 @@ func getMachinePoolReplicas(cmd *cobra.Command,
}

if autoscaling {

// set default values from previous autoscaling values
if !isMinReplicasSet {
minReplicas = existingAutoscaling.MinReplicas()
}
if !isMaxReplicasSet {
maxReplicas = existingAutoscaling.MaxReplicas()
}

// Prompt for min replicas if neither min or max is set or interactive mode
if !isMinReplicasSet && (interactive.Enabled() || !isMaxReplicasSet && askForScalingParams) {
minReplicas, err = interactive.GetInt(interactive.Input{
Question: "Min replicas",
Help: cmd.Flags().Lookup("min-replicas").Usage,
Default: existingAutoscaling.MinReplicas(),
Default: minReplicas,
Required: replicasRequired,
})
if err != nil {
Expand All @@ -183,7 +192,7 @@ func getMachinePoolReplicas(cmd *cobra.Command,
maxReplicas, err = interactive.GetInt(interactive.Input{
Question: "Max replicas",
Help: cmd.Flags().Lookup("max-replicas").Usage,
Default: existingAutoscaling.MaxReplicas(),
Default: maxReplicas,
Required: replicasRequired,
})
if err != nil {
Expand Down Expand Up @@ -222,20 +231,15 @@ func editMachinePoolAutoscaling(machinePool *cmv1.MachinePool,
asBuilder := cmv1.NewMachinePoolAutoscaling()
changed := false

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 >= 0 {
newMax = maxReplicas
changed = true
}

if changed {
asBuilder = asBuilder.MinReplicas(newMin).MaxReplicas(newMax)
asBuilder = asBuilder.MinReplicas(minReplicas).MaxReplicas(maxReplicas)
return asBuilder
}
return nil
Expand Down
10 changes: 0 additions & 10 deletions cmd/edit/machinepool/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ var _ = Describe("Machinepool", func() {
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 967bfb5

Please sign in to comment.