2323package v1alpha
2424
2525import (
26+ "math"
2627 "strings"
2728
2829 "github.com/pkg/errors"
@@ -39,6 +40,10 @@ import (
3940type ServerGroupSpec struct {
4041 // Count holds the requested number of servers
4142 Count * int `json:"count,omitempty"`
43+ // MinCount specifies a lower limit for count
44+ MinCount * int `json:"minCount,omitempty"`
45+ // MaxCount specifies a upper limit for count
46+ MaxCount * int `json:"maxCount,omitempty"`
4247 // Args holds additional commandline arguments
4348 Args []string `json:"args,omitempty"`
4449 // StorageClassName specifies the classname for storage of the servers.
@@ -58,6 +63,16 @@ func (s ServerGroupSpec) GetCount() int {
5863 return util .IntOrDefault (s .Count )
5964}
6065
66+ // GetMinCount returns MinCount or 1 if not set
67+ func (s ServerGroupSpec ) GetMinCount () int {
68+ return util .IntOrDefault (s .MinCount , 1 )
69+ }
70+
71+ // GetMaxCount returns MaxCount or
72+ func (s ServerGroupSpec ) GetMaxCount () int {
73+ return util .IntOrDefault (s .MaxCount , math .MaxInt32 )
74+ }
75+
6176// GetNodeSelector returns the selectors for nodes of this group
6277func (s ServerGroupSpec ) GetNodeSelector () map [string ]string {
6378 return s .NodeSelector
@@ -110,8 +125,17 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
110125 minCount = 2
111126 }
112127 }
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+ }
131+ if s .GetCount () < s .GetMinCount () {
132+ return maskAny (errors .Wrapf (ValidationError , "Invalid count value %d. Expected >= %d" , s .GetCount (), s .GetMinCount ()))
133+ }
134+ if s .GetCount () > s .GetMaxCount () {
135+ return maskAny (errors .Wrapf (ValidationError , "Invalid count value %d. Expected <= %d" , s .GetCount (), s .GetMaxCount ()))
136+ }
113137 if s .GetCount () < minCount {
114- return maskAny (errors .Wrapf (ValidationError , "Invalid count value %d. Expected >= %d" , s .GetCount (), minCount ))
138+ return maskAny (errors .Wrapf (ValidationError , "Invalid count value %d. Expected >= %d (implicit minimum; by deployment mode) " , s .GetCount (), minCount ))
115139 }
116140 if s .GetCount () > 1 && group == ServerGroupSingle && mode == DeploymentModeSingle {
117141 return maskAny (errors .Wrapf (ValidationError , "Invalid count value %d. Expected 1" , s .GetCount ()))
@@ -160,6 +184,8 @@ func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode Deploym
160184 }
161185 } else if s .GetCount () > 0 && ! used {
162186 s .Count = nil
187+ s .MinCount = nil
188+ s .MaxCount = nil
163189 }
164190 if _ , found := s .Resources .Requests [v1 .ResourceStorage ]; ! found {
165191 switch group {
@@ -189,6 +215,12 @@ func (s *ServerGroupSpec) SetDefaultsFrom(source ServerGroupSpec) {
189215 if s .Count == nil {
190216 s .Count = util .NewIntOrNil (source .Count )
191217 }
218+ if s .MinCount == nil {
219+ s .MinCount = util .NewIntOrNil (source .MinCount )
220+ }
221+ if s .MaxCount == nil {
222+ s .MaxCount = util .NewIntOrNil (source .MaxCount )
223+ }
192224 if s .Args == nil {
193225 s .Args = source .Args
194226 }
0 commit comments