From ab8aba1137aba2cf36c292fce2125f44118c21b2 Mon Sep 17 00:00:00 2001 From: Liang Deng <283304489@qq.com> Date: Tue, 30 Jul 2024 14:53:15 +0800 Subject: [PATCH] fix: avoid concurrency is 0 (#7898) Signed-off-by: Liang Deng <283304489@qq.com> (cherry picked from commit 1c81daf73a22805a993854f621ddbcfcab0e2b46) --- pkg/controller/instanceset/utils.go | 3 ++- pkg/controller/instanceset/utils_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/controller/instanceset/utils.go b/pkg/controller/instanceset/utils.go index 8545bd4445c..0b8c175346d 100644 --- a/pkg/controller/instanceset/utils.go +++ b/pkg/controller/instanceset/utils.go @@ -274,6 +274,7 @@ func CalculateConcurrencyReplicas(concurrency *intstr.IntOrString, replicas int) pValue = replicas - 1 } - pValue = integer.IntMax(integer.IntMin(pValue, replicas), 0) + // if the calculated concurrency is 0, it will ensure the concurrency at least 1. + pValue = integer.IntMax(integer.IntMin(pValue, replicas), 1) return pValue, nil } diff --git a/pkg/controller/instanceset/utils_test.go b/pkg/controller/instanceset/utils_test.go index 3f161500693..9f35bbea7f8 100644 --- a/pkg/controller/instanceset/utils_test.go +++ b/pkg/controller/instanceset/utils_test.go @@ -248,14 +248,14 @@ var _ = Describe("utils test", func() { replicas = 0 concurrencyReplicas, err = CalculateConcurrencyReplicas(concurrent, replicas) Expect(err).Should(BeNil()) - Expect(concurrencyReplicas).Should(Equal(0)) + Expect(concurrencyReplicas).Should(Equal(1)) By("concurrency = 0%, replicas = 10") concurrent = &intstr.IntOrString{Type: intstr.String, StrVal: "0%"} replicas = 10 concurrencyReplicas, err = CalculateConcurrencyReplicas(concurrent, replicas) Expect(err).Should(BeNil()) - Expect(concurrencyReplicas).Should(Equal(0)) + Expect(concurrencyReplicas).Should(Equal(1)) By("concurrency = 5, replicas = 10") concurrent = &intstr.IntOrString{Type: intstr.Int, IntVal: 5} @@ -269,14 +269,14 @@ var _ = Describe("utils test", func() { replicas = 0 concurrencyReplicas, err = CalculateConcurrencyReplicas(concurrent, replicas) Expect(err).Should(BeNil()) - Expect(concurrencyReplicas).Should(Equal(0)) + Expect(concurrencyReplicas).Should(Equal(1)) By("concurrency = 0, replicas = 10") concurrent = &intstr.IntOrString{Type: intstr.Int, IntVal: 0} replicas = 10 concurrencyReplicas, err = CalculateConcurrencyReplicas(concurrent, replicas) Expect(err).Should(BeNil()) - Expect(concurrencyReplicas).Should(Equal(0)) + Expect(concurrencyReplicas).Should(Equal(1)) By("concurrency = 10%, replicas = 1") concurrent = &intstr.IntOrString{Type: intstr.String, StrVal: "10%"} @@ -311,7 +311,7 @@ var _ = Describe("utils test", func() { concurrent = &intstr.IntOrString{Type: intstr.String, StrVal: "-50%"} concurrencyReplicas, err = CalculateConcurrencyReplicas(concurrent, replicas) Expect(err).Should(BeNil()) - Expect(concurrencyReplicas).Should(Equal(0)) + Expect(concurrencyReplicas).Should(Equal(1)) By("concurrency percentage > 100%") replicas = 10