From 2da1118aa4d22a4141fb8219613156896cf3789b Mon Sep 17 00:00:00 2001 From: hkepley Date: Tue, 30 Jul 2024 02:13:13 -0400 Subject: [PATCH] OCM-9984 | fix: Change replica (min, max, and normal) minimum to 0 --- pkg/machinepool/validation.go | 12 ++++++------ pkg/machinepool/validation_test.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/machinepool/validation.go b/pkg/machinepool/validation.go index 61145d32bf..ba5c5be72e 100644 --- a/pkg/machinepool/validation.go +++ b/pkg/machinepool/validation.go @@ -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 { diff --git a/pkg/machinepool/validation_test.go b/pkg/machinepool/validation_test.go index 88d916e44c..969fb5d12d 100644 --- a/pkg/machinepool/validation_test.go +++ b/pkg/machinepool/validation_test.go @@ -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() {