Skip to content

Commit

Permalink
fix: avoid concurrency is 0 (#7898)
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Deng <283304489@qq.com>
(cherry picked from commit 1c81daf)
  • Loading branch information
YTGhost authored and free6om committed Jul 30, 2024
1 parent 0afae69 commit ab8aba1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pkg/controller/instanceset/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions pkg/controller/instanceset/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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%"}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab8aba1

Please sign in to comment.