Skip to content

Commit 7f350d4

Browse files
authored
[Feature] Allow to disable member recreation (#761)
1 parent 2879d36 commit 7f350d4

File tree

9 files changed

+74
-10
lines changed

9 files changed

+74
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- Fix ArangoMember race with multiple ArangoDeployments within single namespace
5+
- Allow to define Member Recreation Policy within group
56

67
## [1.2.0](https://github.com/arangodb/kube-arangodb/tree/1.2.0) (2021-07-16)
78
- Enable "Operator Internal Metrics Exporter" by default

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ type DeploymentSpec struct {
163163
CommunicationMethod *DeploymentCommunicationMethod `json:"communicationMethod,omitempty"`
164164
}
165165

166+
// GetAllowMemberRecreation returns member recreation policy based on group and settings
167+
func (s *DeploymentSpec) GetAllowMemberRecreation(group ServerGroup) bool {
168+
if s == nil {
169+
return false
170+
}
171+
172+
groupSpec := s.GetServerGroupSpec(group)
173+
174+
switch group {
175+
case ServerGroupDBServers, ServerGroupCoordinators:
176+
if v := groupSpec.AllowMemberRecreation; v == nil {
177+
return true
178+
} else {
179+
return *v
180+
}
181+
default:
182+
return false
183+
}
184+
}
185+
166186
// GetRestoreFrom returns the restore from string or empty string if not set
167187
func (s *DeploymentSpec) GetRestoreFrom() string {
168188
return util.StringOrDefault(s.RestoreFrom)

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ type ServerGroupSpec struct {
141141
ShutdownDelay *int `json:"shutdownDelay,omitempty"`
142142
// InternalPort define port used in internal communication, can be accessed over localhost via sidecar
143143
InternalPort *int `json:"internalPort,omitempty"`
144+
// AllowMemberRecreation allows to recreate member. Value is used only for Coordinator and DBServer with default to True, for all other groups set to false.
145+
AllowMemberRecreation *bool `json:"allowMemberRecreation,omitempty"`
144146
}
145147

146148
// ServerGroupSpecSecurityContext contains specification for pod security context

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

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

pkg/apis/deployment/v2alpha1/arango_member_spec.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222

2323
package v2alpha1
2424

25-
import core "k8s.io/api/core/v1"
25+
import (
26+
core "k8s.io/api/core/v1"
27+
"k8s.io/apimachinery/pkg/types"
28+
)
2629

2730
type ArangoMemberSpec struct {
28-
Group ServerGroup `json:"group,omitempty"`
29-
ID string `json:"id,omitempty"`
31+
Group ServerGroup `json:"group,omitempty"`
32+
ID string `json:"id,omitempty"`
33+
DeploymentUID types.UID `json:"deploymentUID,omitempty"`
3034

3135
Template *core.PodTemplate `json:"template,omitempty"`
3236
TemplateChecksum string `json:"templateChecksum,omitempty"`

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ type DeploymentSpec struct {
163163
CommunicationMethod *DeploymentCommunicationMethod `json:"communicationMethod,omitempty"`
164164
}
165165

166+
// GetAllowMemberRecreation returns member recreation policy based on group and settings
167+
func (s *DeploymentSpec) GetAllowMemberRecreation(group ServerGroup) bool {
168+
if s == nil {
169+
return false
170+
}
171+
172+
groupSpec := s.GetServerGroupSpec(group)
173+
174+
switch group {
175+
case ServerGroupDBServers, ServerGroupCoordinators:
176+
if v := groupSpec.AllowMemberRecreation; v == nil {
177+
return true
178+
} else {
179+
return *v
180+
}
181+
default:
182+
return false
183+
}
184+
}
185+
166186
// GetRestoreFrom returns the restore from string or empty string if not set
167187
func (s *DeploymentSpec) GetRestoreFrom() string {
168188
return util.StringOrDefault(s.RestoreFrom)

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ type ServerGroupSpec struct {
141141
ShutdownDelay *int `json:"shutdownDelay,omitempty"`
142142
// InternalPort define port used in internal communication, can be accessed over localhost via sidecar
143143
InternalPort *int `json:"internalPort,omitempty"`
144+
// AllowMemberRecreation allows to recreate member. Value is used only for Coordinator and DBServer with default to True, for all other groups set to false.
145+
AllowMemberRecreation *bool `json:"allowMemberRecreation,omitempty"`
144146
}
145147

146148
// ServerGroupSpecSecurityContext contains specification for pod security context

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

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

pkg/deployment/reconcile/plan_builder.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,18 @@ func createPlan(ctx context.Context, log zerolog.Logger, apiObject k8sutil.APIOb
169169
plan = append(plan,
170170
api.NewAction(api.ActionTypeRecreateMember, group, m.ID))
171171
default:
172-
memberLog.Msg("Creating member replacement plan because member has failed")
173-
plan = append(plan,
174-
api.NewAction(api.ActionTypeRemoveMember, group, m.ID),
175-
api.NewAction(api.ActionTypeAddMember, group, ""),
176-
api.NewAction(api.ActionTypeWaitForMemberUp, group, api.MemberIDPreviousAction),
177-
)
178-
172+
if spec.GetAllowMemberRecreation(group) {
173+
memberLog.Msg("Creating member replacement plan because member has failed")
174+
plan = append(plan,
175+
api.NewAction(api.ActionTypeRemoveMember, group, m.ID),
176+
api.NewAction(api.ActionTypeAddMember, group, ""),
177+
api.NewAction(api.ActionTypeWaitForMemberUp, group, api.MemberIDPreviousAction),
178+
)
179+
} else {
180+
memberLog.Msg("Restoring old member. Recreation is disabled for group")
181+
plan = append(plan,
182+
api.NewAction(api.ActionTypeRecreateMember, group, m.ID))
183+
}
179184
}
180185
}
181186
return nil

0 commit comments

Comments
 (0)