Skip to content

Commit

Permalink
OCM-9984 | fix: Change replica (min, max, and normal) minimum to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterkepley committed Jul 30, 2024
1 parent add477a commit 4f04e9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions pkg/machinepool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ func validateCount[K any](kubeletConfigs []K) error {
func validateEditInput(poolType string, autoscaling bool, minReplicas int, maxReplicas int, replicas int,
isReplicasSet bool, isAutoscalingSet bool, isMinReplicasSet bool, isMaxReplicasSet bool, id string) error {

if autoscaling && minReplicas <= 0 && isMinReplicasSet {
return fmt.Errorf("Min replicas must be a positive number when autoscaling is set")
if autoscaling && minReplicas < 0 && isMinReplicasSet {
return fmt.Errorf("Min replicas must be a non-negative number when autoscaling is set")
}

if autoscaling && maxReplicas <= 0 && isMaxReplicasSet {
return fmt.Errorf("Max replicas must be a positive number when autoscaling is set")
if autoscaling && maxReplicas < 0 && isMaxReplicasSet {
return fmt.Errorf("Max replicas must be a non-negative number when autoscaling is set")
}

if !autoscaling && replicas <= 0 {
return fmt.Errorf("Replicas must be a positive number")
if !autoscaling && replicas < 0 {
return fmt.Errorf("Replicas must be a non-negative number")
}

if autoscaling && isReplicasSet && isAutoscalingSet {
Expand Down
8 changes: 4 additions & 4 deletions pkg/machinepool/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ var _ = Describe("MachinePool validation", func() {
2, 1, true, true, true,
true, "test")).ToNot(Succeed())
})
It("Fails with max, min, and replicas <= 0", func() {
Expect(validateEditInput("machine", true, 0,
It("Fails with max, min, and replicas < 0", func() {
Expect(validateEditInput("machine", true, -1,
1, 0, false, true, true,
true, "test")).ToNot(Succeed())
Expect(validateEditInput("machine", true, 1,
0, 0, false, true, true,
-1, 0, false, true, true,
true, "test")).ToNot(Succeed())
Expect(validateEditInput("machine", false, 0,
0, 0, true, true, false,
0, -1, true, true, false,
false, "test")).ToNot(Succeed())
})
It("Fails with max < min replicas", func() {
Expand Down

0 comments on commit 4f04e9a

Please sign in to comment.