Skip to content

Commit fa8d693

Browse files
author
lamai93
committed
Check min > max.
1 parent af549fd commit fa8d693

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pkg/apis/deployment/v1alpha/server_group_spec.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,12 @@ func (s ServerGroupSpec) GetCount() int {
6565

6666
// GetMinCount returns MinCount or 1 if not set
6767
func (s ServerGroupSpec) GetMinCount() int {
68-
if s.MinCount != nil {
69-
return *s.MinCount
70-
}
71-
return 1
68+
return util.IntOrDefault(s.MinCount, 1)
7269
}
7370

7471
// GetMaxCount returns MaxCount or
7572
func (s ServerGroupSpec) GetMaxCount() int {
76-
if s.MaxCount != nil {
77-
return *s.MaxCount
78-
}
79-
return math.MaxInt32
73+
return util.IntOrDefault(s.MaxCount, math.MaxInt32)
8074
}
8175

8276
// GetNodeSelector returns the selectors for nodes of this group
@@ -131,6 +125,9 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
131125
minCount = 2
132126
}
133127
}
128+
if s.GetMinCount() > s.GetMaxCount() {
129+
return maskAny(errors.Wrapf(ValidationError, "Invalid min/maxCount. Min (%d) bigger than Max (%d)", s.GetMinCount(), s.GetMaxCount()))
130+
}
134131
if s.GetCount() < s.GetMinCount() {
135132
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), s.GetMinCount()))
136133
}

0 commit comments

Comments
 (0)