File tree 2 files changed +23
-8
lines changed
2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ limitations under the License.
17
17
package v1alpha1
18
18
19
19
import (
20
- "math"
21
-
22
20
corev1 "k8s.io/api/core/v1"
23
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
22
"k8s.io/apimachinery/pkg/util/intstr"
@@ -84,12 +82,7 @@ type EtcdCluster struct {
84
82
85
83
// CalculateQuorumSize returns minimum quorum size for current number of replicas
86
84
func (r * EtcdCluster ) CalculateQuorumSize () int {
87
- replicas := * r .Spec .Replicas
88
- if replicas % 2 == 0 {
89
- replicas = replicas + 1
90
- }
91
-
92
- return int (math .Ceil (float64 (replicas ) / 2. ))
85
+ return int (* r .Spec .Replicas )/ 2 + 1
93
86
}
94
87
95
88
// +kubebuilder:object:root=true
Original file line number Diff line number Diff line change
1
+ package v1alpha1
2
+
3
+ import (
4
+ . "github.com/onsi/ginkgo/v2"
5
+ . "github.com/onsi/gomega"
6
+ "k8s.io/utils/ptr"
7
+ )
8
+
9
+ var _ = Context ("CalculateQuorumSize" , func () {
10
+ It ("should return correct result for odd number of replicas" , func () {
11
+ etcdCluster := EtcdCluster {
12
+ Spec : EtcdClusterSpec {Replicas : ptr .To (int32 (3 ))},
13
+ }
14
+ Expect (etcdCluster .CalculateQuorumSize ()).To (Equal (2 ))
15
+ })
16
+ It ("should return correct result for even number of replicas" , func () {
17
+ etcdCluster := EtcdCluster {
18
+ Spec : EtcdClusterSpec {Replicas : ptr .To (int32 (4 ))},
19
+ }
20
+ Expect (etcdCluster .CalculateQuorumSize ()).To (Equal (3 ))
21
+ })
22
+ })
You can’t perform that action at this time.
0 commit comments