Skip to content

Commit af549fd

Browse files
author
lamai93
committed
Added test. Added helper functions. Updated documentation.
1 parent 4577e15 commit af549fd

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

docs/Manual/Deployment/Kubernetes/DeploymentResource.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ for `spec.mode: Single` and `2` for `spec.mode: ActiveFailover`).
352352
For the `syncworkers` group, it is highly recommended to use the same number
353353
as for the `dbservers` group.
354354

355+
### `spec.<group>.minCount: number`
356+
357+
Specifies a minimum for the count of servers. If set, a specification is invalid if `count < minCount`.
358+
359+
### `spec.<group>.maxCount: number`
360+
361+
Specifies a maximum for the count of servers. If set, a specification is invalid if `count > maxCount`.
362+
355363
### `spec.<group>.args: []string`
356364

357365
This setting specifies additional commandline arguments passed to all servers of this group.

pkg/apis/deployment/v1alpha/server_group_spec.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package v1alpha
2424

2525
import (
26+
"math"
2627
"strings"
2728

2829
"github.com/pkg/errors"
@@ -62,6 +63,22 @@ func (s ServerGroupSpec) GetCount() int {
6263
return util.IntOrDefault(s.Count)
6364
}
6465

66+
// GetMinCount returns MinCount or 1 if not set
67+
func (s ServerGroupSpec) GetMinCount() int {
68+
if s.MinCount != nil {
69+
return *s.MinCount
70+
}
71+
return 1
72+
}
73+
74+
// GetMaxCount returns MaxCount or
75+
func (s ServerGroupSpec) GetMaxCount() int {
76+
if s.MaxCount != nil {
77+
return *s.MaxCount
78+
}
79+
return math.MaxInt32
80+
}
81+
6582
// GetNodeSelector returns the selectors for nodes of this group
6683
func (s ServerGroupSpec) GetNodeSelector() map[string]string {
6784
return s.NodeSelector
@@ -114,24 +131,11 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
114131
minCount = 2
115132
}
116133
}
117-
var specMinCount int
118-
if s.MinCount != nil {
119-
specMinCount = *s.MinCount
120-
if specMinCount < 1 {
121-
return maskAny(errors.Wrapf(ValidationError, "Invalid minCount: %d < 1", specMinCount))
122-
}
123-
if s.GetCount() < specMinCount {
124-
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), specMinCount))
125-
}
134+
if s.GetCount() < s.GetMinCount() {
135+
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), s.GetMinCount()))
126136
}
127-
if s.MaxCount != nil {
128-
specMaxCount := *s.MaxCount
129-
if specMaxCount < specMinCount {
130-
return maskAny(errors.Wrapf(ValidationError, "Invalid maxCount: (maxCount) %d < %d (minCount)", specMaxCount, specMinCount))
131-
}
132-
if s.GetCount() > specMaxCount {
133-
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected <= %d", s.GetCount(), specMaxCount))
134-
}
137+
if s.GetCount() > s.GetMaxCount() {
138+
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected <= %d", s.GetCount(), s.GetMaxCount()))
135139
}
136140
if s.GetCount() < minCount {
137141
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d (implicit minimum; by deployment mode)", s.GetCount(), minCount))

pkg/apis/deployment/v1alpha/server_group_spec_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestServerGroupSpecValidateCount(t *testing.T) {
5151
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
5252
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
5353
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6), MinCount: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
54+
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(5), MinCount: util.NewInt(5), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
5455
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
5556

5657
// Invalid

0 commit comments

Comments
 (0)