Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/Manual/Deployment/Kubernetes/DeploymentResource.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ for `spec.mode: Single` and `2` for `spec.mode: ActiveFailover`).
For the `syncworkers` group, it is highly recommended to use the same number
as for the `dbservers` group.

### `spec.<group>.minCount: number`

Specifies a minimum for the count of servers. If set, a specification is invalid if `count < minCount`.

### `spec.<group>.maxCount: number`

Specifies a maximum for the count of servers. If set, a specification is invalid if `count > maxCount`.

### `spec.<group>.args: []string`

This setting specifies additional commandline arguments passed to all servers of this group.
Expand Down
34 changes: 33 additions & 1 deletion pkg/apis/deployment/v1alpha/server_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package v1alpha

import (
"math"
"strings"

"github.com/pkg/errors"
Expand All @@ -39,6 +40,10 @@ import (
type ServerGroupSpec struct {
// Count holds the requested number of servers
Count *int `json:"count,omitempty"`
// MinCount specifies a lower limit for count
MinCount *int `json:"minCount,omitempty"`
// MaxCount specifies a upper limit for count
MaxCount *int `json:"maxCount,omitempty"`
// Args holds additional commandline arguments
Args []string `json:"args,omitempty"`
// StorageClassName specifies the classname for storage of the servers.
Expand All @@ -58,6 +63,16 @@ func (s ServerGroupSpec) GetCount() int {
return util.IntOrDefault(s.Count)
}

// GetMinCount returns MinCount or 1 if not set
func (s ServerGroupSpec) GetMinCount() int {
return util.IntOrDefault(s.MinCount, 1)
}

// GetMaxCount returns MaxCount or
func (s ServerGroupSpec) GetMaxCount() int {
return util.IntOrDefault(s.MaxCount, math.MaxInt32)
}

// GetNodeSelector returns the selectors for nodes of this group
func (s ServerGroupSpec) GetNodeSelector() map[string]string {
return s.NodeSelector
Expand Down Expand Up @@ -110,8 +125,17 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
minCount = 2
}
}
if s.GetMinCount() > s.GetMaxCount() {
return maskAny(errors.Wrapf(ValidationError, "Invalid min/maxCount. Min (%d) bigger than Max (%d)", s.GetMinCount(), s.GetMaxCount()))
}
if s.GetCount() < s.GetMinCount() {
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), s.GetMinCount()))
}
if s.GetCount() > s.GetMaxCount() {
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected <= %d", s.GetCount(), s.GetMaxCount()))
}
if s.GetCount() < minCount {
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), minCount))
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d (implicit minimum; by deployment mode)", s.GetCount(), minCount))
}
if s.GetCount() > 1 && group == ServerGroupSingle && mode == DeploymentModeSingle {
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected 1", s.GetCount()))
Expand Down Expand Up @@ -160,6 +184,8 @@ func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode Deploym
}
} else if s.GetCount() > 0 && !used {
s.Count = nil
s.MinCount = nil
s.MaxCount = nil
}
if _, found := s.Resources.Requests[v1.ResourceStorage]; !found {
switch group {
Expand Down Expand Up @@ -189,6 +215,12 @@ func (s *ServerGroupSpec) SetDefaultsFrom(source ServerGroupSpec) {
if s.Count == nil {
s.Count = util.NewIntOrNil(source.Count)
}
if s.MinCount == nil {
s.MinCount = util.NewIntOrNil(source.MinCount)
}
if s.MaxCount == nil {
s.MaxCount = util.NewIntOrNil(source.MaxCount)
}
if s.Args == nil {
s.Args = source.Args
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/deployment/v1alpha/server_group_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func TestServerGroupSpecValidateCount(t *testing.T) {
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction))
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction))

assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6), MinCount: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(5), MinCount: util.NewInt(5), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))

// Invalid
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment))
assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment))
Expand All @@ -70,6 +76,11 @@ func TestServerGroupSpecValidateCount(t *testing.T) {
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction))
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction))
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction))

assert.Error(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(5), MaxCount: util.NewInt(1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
assert.Error(t, ServerGroupSpec{Count: util.NewInt(6), MaxCount: util.NewInt(5)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))
assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), MinCount: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment))

}

func TestServerGroupSpecDefault(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/deployment/cluster_scaling_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
if dbserversChanged {
newSpec.DBServers.Count = util.NewInt(req.GetDBServers())
}
// Validate will additionally check if
// min <= count <= max holds for the given server groups
if err := newSpec.Validate(); err != nil {
// Log failure & create event
log.Warn().Err(err).Msg("Validation of updated spec has failed")
Expand Down