Skip to content

Commit 4577e15

Browse files
author
lamai93
committed
Added scaling limits.
1 parent 075dbf8 commit 4577e15

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

pkg/apis/deployment/v1alpha/server_group_spec.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import (
3939
type ServerGroupSpec struct {
4040
// Count holds the requested number of servers
4141
Count *int `json:"count,omitempty"`
42+
// MinCount specifies a lower limit for count
43+
MinCount *int `json:"minCount,omitempty"`
44+
// MaxCount specifies a upper limit for count
45+
MaxCount *int `json:"maxCount,omitempty"`
4246
// Args holds additional commandline arguments
4347
Args []string `json:"args,omitempty"`
4448
// StorageClassName specifies the classname for storage of the servers.
@@ -110,8 +114,27 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
110114
minCount = 2
111115
}
112116
}
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+
}
126+
}
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+
}
135+
}
113136
if s.GetCount() < minCount {
114-
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), minCount))
137+
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d (implicit minimum; by deployment mode)", s.GetCount(), minCount))
115138
}
116139
if s.GetCount() > 1 && group == ServerGroupSingle && mode == DeploymentModeSingle {
117140
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected 1", s.GetCount()))
@@ -160,6 +183,8 @@ func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode Deploym
160183
}
161184
} else if s.GetCount() > 0 && !used {
162185
s.Count = nil
186+
s.MinCount = nil
187+
s.MaxCount = nil
163188
}
164189
if _, found := s.Resources.Requests[v1.ResourceStorage]; !found {
165190
switch group {
@@ -189,6 +214,12 @@ func (s *ServerGroupSpec) SetDefaultsFrom(source ServerGroupSpec) {
189214
if s.Count == nil {
190215
s.Count = util.NewIntOrNil(source.Count)
191216
}
217+
if s.MinCount == nil {
218+
s.MinCount = util.NewIntOrNil(source.MinCount)
219+
}
220+
if s.MaxCount == nil {
221+
s.MaxCount = util.NewIntOrNil(source.MaxCount)
222+
}
192223
if s.Args == nil {
193224
s.Args = source.Args
194225
}

pkg/apis/deployment/v1alpha/server_group_spec_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func TestServerGroupSpecValidateCount(t *testing.T) {
4848
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction))
4949
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction))
5050

51+
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
52+
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
53+
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(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
55+
5156
// Invalid
5257
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment))
5358
assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment))
@@ -70,6 +75,11 @@ func TestServerGroupSpecValidateCount(t *testing.T) {
7075
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction))
7176
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction))
7277
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction))
78+
79+
assert.Error(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(5), MaxCount: util.NewInt(1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
80+
assert.Error(t, ServerGroupSpec{Count: util.NewInt(6), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
81+
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), MinCount: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
82+
7383
}
7484

7585
func TestServerGroupSpecDefault(t *testing.T) {

pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/cluster_scaling_integration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
170170
if dbserversChanged {
171171
newSpec.DBServers.Count = util.NewInt(req.GetDBServers())
172172
}
173+
// Validate will additionally check if
174+
// min <= count <= max holds for the given server groups
173175
if err := newSpec.Validate(); err != nil {
174176
// Log failure & create event
175177
log.Warn().Err(err).Msg("Validation of updated spec has failed")

0 commit comments

Comments
 (0)