|
23 | 23 | package v1alpha |
24 | 24 |
|
25 | 25 | import ( |
| 26 | + "math" |
26 | 27 | "strings" |
27 | 28 |
|
28 | 29 | "github.com/pkg/errors" |
@@ -62,6 +63,22 @@ func (s ServerGroupSpec) GetCount() int { |
62 | 63 | return util.IntOrDefault(s.Count) |
63 | 64 | } |
64 | 65 |
|
| 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 | + |
65 | 82 | // GetNodeSelector returns the selectors for nodes of this group |
66 | 83 | func (s ServerGroupSpec) GetNodeSelector() map[string]string { |
67 | 84 | return s.NodeSelector |
@@ -114,24 +131,11 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM |
114 | 131 | minCount = 2 |
115 | 132 | } |
116 | 133 | } |
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())) |
126 | 136 | } |
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())) |
135 | 139 | } |
136 | 140 | if s.GetCount() < minCount { |
137 | 141 | return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d (implicit minimum; by deployment mode)", s.GetCount(), minCount)) |
|
0 commit comments