From 565da298f1f3223f1a69ffd09c3464915321a2b1 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:18:06 +0100 Subject: [PATCH] [Improvement] Add ServerGroup details into ServerGroupSpec (#1191) --- CHANGELOG.md | 1 + pkg/apis/deployment/v1/deployment_spec.go | 12 +- pkg/apis/deployment/v1/server_group_spec.go | 35 +++++- .../deployment/v1/server_group_spec_test.go | 106 +++++++++--------- pkg/apis/deployment/v2alpha1/conditions.go | 2 + .../deployment/v2alpha1/deployment_spec.go | 12 +- .../deployment/v2alpha1/server_group_spec.go | 35 +++++- .../v2alpha1/server_group_spec_test.go | 106 +++++++++--------- 8 files changed, 189 insertions(+), 120 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e25fc0480..d90ca43dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - (Bugfix) Check ArangoSync availability without checking healthiness - (Improvement) Add Anonymous Inspector mods - (Improvement) Do not check checksums for DeploymentReplicationStatus.IncomingSynchronization field values +- (Improvement) Add ServerGroup details into ServerGroupSpec ## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25) - (Feature) Add action progress diff --git a/pkg/apis/deployment/v1/deployment_spec.go b/pkg/apis/deployment/v1/deployment_spec.go index a69143098..9aaab2016 100644 --- a/pkg/apis/deployment/v1/deployment_spec.go +++ b/pkg/apis/deployment/v1/deployment_spec.go @@ -286,17 +286,17 @@ func (s DeploymentSpec) IsSecure() bool { func (s DeploymentSpec) GetServerGroupSpec(group ServerGroup) ServerGroupSpec { switch group { case ServerGroupSingle: - return s.Single + return s.Single.WithGroup(group) case ServerGroupAgents: - return s.Agents + return s.Agents.WithGroup(group) case ServerGroupDBServers: - return s.DBServers + return s.DBServers.WithGroup(group) case ServerGroupCoordinators: - return s.Coordinators + return s.Coordinators.WithGroup(group) case ServerGroupSyncMasters: - return s.SyncMasters + return s.SyncMasters.WithGroup(group) case ServerGroupSyncWorkers: - return s.SyncWorkers + return s.SyncWorkers.WithGroup(group) default: return ServerGroupSpec{} } diff --git a/pkg/apis/deployment/v1/server_group_spec.go b/pkg/apis/deployment/v1/server_group_spec.go index 44e84a86d..2e3c1df18 100644 --- a/pkg/apis/deployment/v1/server_group_spec.go +++ b/pkg/apis/deployment/v1/server_group_spec.go @@ -66,6 +66,8 @@ const ( // ServerGroupSpec contains the specification for all servers in a specific group (e.g. all agents) type ServerGroupSpec struct { + group ServerGroup `json:"-"` + // Count holds the requested number of servers Count *int `json:"count,omitempty"` // MinCount specifies a lower limit for count @@ -343,7 +345,7 @@ func (s ServerGroupSpec) GetOverrideDetectedTotalMemory() bool { return *s.OverrideDetectedTotalMemory } -// OverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false) +// GetOverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false) func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool { if s.OverrideDetectedNumberOfCores == nil { return true @@ -354,6 +356,10 @@ func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool { // Validate the given group spec func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentMode, env Environment) error { + if s.group != group { + return errors.WithStack(errors.Wrapf(ValidationError, "Group is not set")) + } + if used { minCount := 1 if env == EnvironmentProduction { @@ -484,8 +490,27 @@ func (s *ServerGroupSpec) validateVolumes() error { return nil } +// WithGroup copy deployment with missing group +func (s ServerGroupSpec) WithGroup(group ServerGroup) ServerGroupSpec { + s.group = group + return s +} + +// WithDefaults copy deployment with missing defaults +func (s ServerGroupSpec) WithDefaults(group ServerGroup, used bool, mode DeploymentMode) ServerGroupSpec { + q := s.DeepCopy() + q.SetDefaults(group, used, mode) + return *q +} + // SetDefaults fills in missing defaults func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode DeploymentMode) { + if s == nil { + return + } + + s.group = group + if s.GetCount() == 0 && used { switch group { case ServerGroupSingle: @@ -636,3 +661,11 @@ func (s ServerGroupSpec) GetExternalPortEnabled() bool { return *v } } + +func (s *ServerGroupSpec) Group() ServerGroup { + if s == nil { + return ServerGroupUnknown + } + + return s.group +} diff --git a/pkg/apis/deployment/v1/server_group_spec_test.go b/pkg/apis/deployment/v1/server_group_spec_test.go index 0c3aade3b..4846450df 100644 --- a/pkg/apis/deployment/v1/server_group_spec_test.go +++ b/pkg/apis/deployment/v1/server_group_spec_test.go @@ -30,55 +30,55 @@ import ( func TestServerGroupSpecValidateCount(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) - 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(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncWorkers).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)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(5), MinCount: util.NewInt(5), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).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)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - 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(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncWorkers).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)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(5), MaxCount: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(6), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) } @@ -120,13 +120,13 @@ func TestServerGroupSpecDefault(t *testing.T) { func TestServerGroupSpecValidateArgs(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint"}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) // Invalid - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication", "true"}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint=http://something"}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--mq.type=strange"}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication", "true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) } diff --git a/pkg/apis/deployment/v2alpha1/conditions.go b/pkg/apis/deployment/v2alpha1/conditions.go index 891e6c857..08b1b319b 100644 --- a/pkg/apis/deployment/v2alpha1/conditions.go +++ b/pkg/apis/deployment/v2alpha1/conditions.go @@ -78,6 +78,8 @@ const ( ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed" // ConditionTypeArchitectureMismatch indicates that the member has a different architecture than the deployment. ConditionTypeArchitectureMismatch ConditionType = "ArchitectureMismatch" + // ConditionTypeArchitectureChangeCannotBeApplied indicates that the member has a different architecture than the requested one. + ConditionTypeArchitectureChangeCannotBeApplied ConditionType = "ArchitectureChangeCannotBeApplied" // ConditionTypeMemberMaintenanceMode indicates that Maintenance is enabled on particular member ConditionTypeMemberMaintenanceMode ConditionType = "MemberMaintenanceMode" diff --git a/pkg/apis/deployment/v2alpha1/deployment_spec.go b/pkg/apis/deployment/v2alpha1/deployment_spec.go index 4fda05c62..55bb3fdc0 100644 --- a/pkg/apis/deployment/v2alpha1/deployment_spec.go +++ b/pkg/apis/deployment/v2alpha1/deployment_spec.go @@ -286,17 +286,17 @@ func (s DeploymentSpec) IsSecure() bool { func (s DeploymentSpec) GetServerGroupSpec(group ServerGroup) ServerGroupSpec { switch group { case ServerGroupSingle: - return s.Single + return s.Single.WithGroup(group) case ServerGroupAgents: - return s.Agents + return s.Agents.WithGroup(group) case ServerGroupDBServers: - return s.DBServers + return s.DBServers.WithGroup(group) case ServerGroupCoordinators: - return s.Coordinators + return s.Coordinators.WithGroup(group) case ServerGroupSyncMasters: - return s.SyncMasters + return s.SyncMasters.WithGroup(group) case ServerGroupSyncWorkers: - return s.SyncWorkers + return s.SyncWorkers.WithGroup(group) default: return ServerGroupSpec{} } diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec.go b/pkg/apis/deployment/v2alpha1/server_group_spec.go index ab28f9fd6..e8282aa88 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec.go @@ -66,6 +66,8 @@ const ( // ServerGroupSpec contains the specification for all servers in a specific group (e.g. all agents) type ServerGroupSpec struct { + group ServerGroup `json:"-"` + // Count holds the requested number of servers Count *int `json:"count,omitempty"` // MinCount specifies a lower limit for count @@ -343,7 +345,7 @@ func (s ServerGroupSpec) GetOverrideDetectedTotalMemory() bool { return *s.OverrideDetectedTotalMemory } -// OverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false) +// GetOverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false) func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool { if s.OverrideDetectedNumberOfCores == nil { return true @@ -354,6 +356,10 @@ func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool { // Validate the given group spec func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentMode, env Environment) error { + if s.group != group { + return errors.WithStack(errors.Wrapf(ValidationError, "Group is not set")) + } + if used { minCount := 1 if env == EnvironmentProduction { @@ -484,8 +490,27 @@ func (s *ServerGroupSpec) validateVolumes() error { return nil } +// WithGroup copy deployment with missing group +func (s ServerGroupSpec) WithGroup(group ServerGroup) ServerGroupSpec { + s.group = group + return s +} + +// WithDefaults copy deployment with missing defaults +func (s ServerGroupSpec) WithDefaults(group ServerGroup, used bool, mode DeploymentMode) ServerGroupSpec { + q := s.DeepCopy() + q.SetDefaults(group, used, mode) + return *q +} + // SetDefaults fills in missing defaults func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode DeploymentMode) { + if s == nil { + return + } + + s.group = group + if s.GetCount() == 0 && used { switch group { case ServerGroupSingle: @@ -636,3 +661,11 @@ func (s ServerGroupSpec) GetExternalPortEnabled() bool { return *v } } + +func (s *ServerGroupSpec) Group() ServerGroup { + if s == nil { + return ServerGroupUnknown + } + + return s.group +} diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec_test.go b/pkg/apis/deployment/v2alpha1/server_group_spec_test.go index 6369770f0..253254803 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec_test.go @@ -30,55 +30,55 @@ import ( func TestServerGroupSpecValidateCount(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) - 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(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncWorkers).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)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(5), MinCount: util.NewInt(5), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).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)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - 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(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncWorkers).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)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(5), MaxCount: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(6), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) } @@ -120,13 +120,13 @@ func TestServerGroupSpecDefault(t *testing.T) { func TestServerGroupSpecValidateArgs(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint"}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) // Invalid - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication", "true"}}.Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint=http://something"}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--mq.type=strange"}}.Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication", "true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) }