Skip to content

Commit 565da29

Browse files
authored
[Improvement] Add ServerGroup details into ServerGroupSpec (#1191)
1 parent c9fadb3 commit 565da29

File tree

8 files changed

+193
-124
lines changed

8 files changed

+193
-124
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- (Bugfix) Check ArangoSync availability without checking healthiness
2727
- (Improvement) Add Anonymous Inspector mods
2828
- (Improvement) Do not check checksums for DeploymentReplicationStatus.IncomingSynchronization field values
29+
- (Improvement) Add ServerGroup details into ServerGroupSpec
2930

3031
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
3132
- (Feature) Add action progress

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,17 @@ func (s DeploymentSpec) IsSecure() bool {
286286
func (s DeploymentSpec) GetServerGroupSpec(group ServerGroup) ServerGroupSpec {
287287
switch group {
288288
case ServerGroupSingle:
289-
return s.Single
289+
return s.Single.WithGroup(group)
290290
case ServerGroupAgents:
291-
return s.Agents
291+
return s.Agents.WithGroup(group)
292292
case ServerGroupDBServers:
293-
return s.DBServers
293+
return s.DBServers.WithGroup(group)
294294
case ServerGroupCoordinators:
295-
return s.Coordinators
295+
return s.Coordinators.WithGroup(group)
296296
case ServerGroupSyncMasters:
297-
return s.SyncMasters
297+
return s.SyncMasters.WithGroup(group)
298298
case ServerGroupSyncWorkers:
299-
return s.SyncWorkers
299+
return s.SyncWorkers.WithGroup(group)
300300
default:
301301
return ServerGroupSpec{}
302302
}

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const (
6666

6767
// ServerGroupSpec contains the specification for all servers in a specific group (e.g. all agents)
6868
type ServerGroupSpec struct {
69+
group ServerGroup `json:"-"`
70+
6971
// Count holds the requested number of servers
7072
Count *int `json:"count,omitempty"`
7173
// MinCount specifies a lower limit for count
@@ -343,7 +345,7 @@ func (s ServerGroupSpec) GetOverrideDetectedTotalMemory() bool {
343345
return *s.OverrideDetectedTotalMemory
344346
}
345347

346-
// OverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false)
348+
// GetOverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false)
347349
func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool {
348350
if s.OverrideDetectedNumberOfCores == nil {
349351
return true
@@ -354,6 +356,10 @@ func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool {
354356

355357
// Validate the given group spec
356358
func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentMode, env Environment) error {
359+
if s.group != group {
360+
return errors.WithStack(errors.Wrapf(ValidationError, "Group is not set"))
361+
}
362+
357363
if used {
358364
minCount := 1
359365
if env == EnvironmentProduction {
@@ -484,8 +490,27 @@ func (s *ServerGroupSpec) validateVolumes() error {
484490
return nil
485491
}
486492

493+
// WithGroup copy deployment with missing group
494+
func (s ServerGroupSpec) WithGroup(group ServerGroup) ServerGroupSpec {
495+
s.group = group
496+
return s
497+
}
498+
499+
// WithDefaults copy deployment with missing defaults
500+
func (s ServerGroupSpec) WithDefaults(group ServerGroup, used bool, mode DeploymentMode) ServerGroupSpec {
501+
q := s.DeepCopy()
502+
q.SetDefaults(group, used, mode)
503+
return *q
504+
}
505+
487506
// SetDefaults fills in missing defaults
488507
func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode DeploymentMode) {
508+
if s == nil {
509+
return
510+
}
511+
512+
s.group = group
513+
489514
if s.GetCount() == 0 && used {
490515
switch group {
491516
case ServerGroupSingle:
@@ -636,3 +661,11 @@ func (s ServerGroupSpec) GetExternalPortEnabled() bool {
636661
return *v
637662
}
638663
}
664+
665+
func (s *ServerGroupSpec) Group() ServerGroup {
666+
if s == nil {
667+
return ServerGroupUnknown
668+
}
669+
670+
return s.group
671+
}

pkg/apis/deployment/v1/server_group_spec_test.go

Lines changed: 55 additions & 55 deletions
Large diffs are not rendered by default.

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const (
7878
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"
7979
// ConditionTypeArchitectureMismatch indicates that the member has a different architecture than the deployment.
8080
ConditionTypeArchitectureMismatch ConditionType = "ArchitectureMismatch"
81+
// ConditionTypeArchitectureChangeCannotBeApplied indicates that the member has a different architecture than the requested one.
82+
ConditionTypeArchitectureChangeCannotBeApplied ConditionType = "ArchitectureChangeCannotBeApplied"
8183

8284
// ConditionTypeMemberMaintenanceMode indicates that Maintenance is enabled on particular member
8385
ConditionTypeMemberMaintenanceMode ConditionType = "MemberMaintenanceMode"

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,17 @@ func (s DeploymentSpec) IsSecure() bool {
286286
func (s DeploymentSpec) GetServerGroupSpec(group ServerGroup) ServerGroupSpec {
287287
switch group {
288288
case ServerGroupSingle:
289-
return s.Single
289+
return s.Single.WithGroup(group)
290290
case ServerGroupAgents:
291-
return s.Agents
291+
return s.Agents.WithGroup(group)
292292
case ServerGroupDBServers:
293-
return s.DBServers
293+
return s.DBServers.WithGroup(group)
294294
case ServerGroupCoordinators:
295-
return s.Coordinators
295+
return s.Coordinators.WithGroup(group)
296296
case ServerGroupSyncMasters:
297-
return s.SyncMasters
297+
return s.SyncMasters.WithGroup(group)
298298
case ServerGroupSyncWorkers:
299-
return s.SyncWorkers
299+
return s.SyncWorkers.WithGroup(group)
300300
default:
301301
return ServerGroupSpec{}
302302
}

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const (
6666

6767
// ServerGroupSpec contains the specification for all servers in a specific group (e.g. all agents)
6868
type ServerGroupSpec struct {
69+
group ServerGroup `json:"-"`
70+
6971
// Count holds the requested number of servers
7072
Count *int `json:"count,omitempty"`
7173
// MinCount specifies a lower limit for count
@@ -343,7 +345,7 @@ func (s ServerGroupSpec) GetOverrideDetectedTotalMemory() bool {
343345
return *s.OverrideDetectedTotalMemory
344346
}
345347

346-
// OverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false)
348+
// GetOverrideDetectedNumberOfCores returns OverrideDetectedNumberOfCores with default value (false)
347349
func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool {
348350
if s.OverrideDetectedNumberOfCores == nil {
349351
return true
@@ -354,6 +356,10 @@ func (s ServerGroupSpec) GetOverrideDetectedNumberOfCores() bool {
354356

355357
// Validate the given group spec
356358
func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentMode, env Environment) error {
359+
if s.group != group {
360+
return errors.WithStack(errors.Wrapf(ValidationError, "Group is not set"))
361+
}
362+
357363
if used {
358364
minCount := 1
359365
if env == EnvironmentProduction {
@@ -484,8 +490,27 @@ func (s *ServerGroupSpec) validateVolumes() error {
484490
return nil
485491
}
486492

493+
// WithGroup copy deployment with missing group
494+
func (s ServerGroupSpec) WithGroup(group ServerGroup) ServerGroupSpec {
495+
s.group = group
496+
return s
497+
}
498+
499+
// WithDefaults copy deployment with missing defaults
500+
func (s ServerGroupSpec) WithDefaults(group ServerGroup, used bool, mode DeploymentMode) ServerGroupSpec {
501+
q := s.DeepCopy()
502+
q.SetDefaults(group, used, mode)
503+
return *q
504+
}
505+
487506
// SetDefaults fills in missing defaults
488507
func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode DeploymentMode) {
508+
if s == nil {
509+
return
510+
}
511+
512+
s.group = group
513+
489514
if s.GetCount() == 0 && used {
490515
switch group {
491516
case ServerGroupSingle:
@@ -636,3 +661,11 @@ func (s ServerGroupSpec) GetExternalPortEnabled() bool {
636661
return *v
637662
}
638663
}
664+
665+
func (s *ServerGroupSpec) Group() ServerGroup {
666+
if s == nil {
667+
return ServerGroupUnknown
668+
}
669+
670+
return s.group
671+
}

0 commit comments

Comments
 (0)