Skip to content

Commit f124f5f

Browse files
authored
[Feature] SilentRotation High plan (#1238)
1 parent 475987a commit f124f5f

26 files changed

+276
-167
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- (Feature) Add Kubernetes Client logger
66
- (Feature) CreationFailed ArangoMember Phase
77
- (Bugfix) Fix Rebalancer NPE in case if member is missing in Status
8+
- (Feature) SilentRotation High plan
89

910
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
1011
- (Bugfix) Fix deployment creation on ARM64

pkg/apis/deployment/v1/plan.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -170,6 +170,12 @@ func NewAction(actionType ActionType, group ServerGroup, memberID string, reason
170170
type ActionBuilder interface {
171171
// NewAction instantiates a new Action.
172172
NewAction(actionType ActionType, reason ...string) Action
173+
174+
// Group returns ServerGroup for this builder
175+
Group() ServerGroup
176+
177+
// MemberID returns Member ID for this builder
178+
MemberID() string
173179
}
174180

175181
type actionBuilder struct {
@@ -181,6 +187,14 @@ func (a actionBuilder) NewAction(actionType ActionType, reason ...string) Action
181187
return NewAction(actionType, a.group, a.memberID, reason...)
182188
}
183189

190+
func (a actionBuilder) Group() ServerGroup {
191+
return a.group
192+
}
193+
194+
func (a actionBuilder) MemberID() string {
195+
return a.memberID
196+
}
197+
184198
// NewActionBuilder create new action builder with provided group and id
185199
func NewActionBuilder(group ServerGroup, memberID string) ActionBuilder {
186200
return actionBuilder{

pkg/apis/deployment/v2alpha1/plan.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -170,6 +170,12 @@ func NewAction(actionType ActionType, group ServerGroup, memberID string, reason
170170
type ActionBuilder interface {
171171
// NewAction instantiates a new Action.
172172
NewAction(actionType ActionType, reason ...string) Action
173+
174+
// Group returns ServerGroup for this builder
175+
Group() ServerGroup
176+
177+
// MemberID returns Member ID for this builder
178+
MemberID() string
173179
}
174180

175181
type actionBuilder struct {
@@ -181,6 +187,14 @@ func (a actionBuilder) NewAction(actionType ActionType, reason ...string) Action
181187
return NewAction(actionType, a.group, a.memberID, reason...)
182188
}
183189

190+
func (a actionBuilder) Group() ServerGroup {
191+
return a.group
192+
}
193+
194+
func (a actionBuilder) MemberID() string {
195+
return a.memberID
196+
}
197+
184198
// NewActionBuilder create new action builder with provided group and id
185199
func NewActionBuilder(group ServerGroup, memberID string) ActionBuilder {
186200
return actionBuilder{

pkg/deployment/actions/wrapper.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -47,6 +47,14 @@ func (a actionBuilderWrap) NewAction(actionType api.ActionType, reason ...string
4747
return NewAction(actionType, a.group, a.member, reason...)
4848
}
4949

50+
func (a actionBuilderWrap) Group() api.ServerGroup {
51+
return a.group
52+
}
53+
54+
func (a actionBuilderWrap) MemberID() string {
55+
return a.member.ID
56+
}
57+
5058
func actionWrap(a api.Action, member *api.MemberStatus, wrap ...actionWrapper) api.Action {
5159
for _, w := range wrap {
5260
a = w(a, member)

pkg/deployment/reconcile/action_add_member.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import (
2424
"context"
2525

2626
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
2728
"github.com/arangodb/kube-arangodb/pkg/deployment/topology"
2829
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2930
)
@@ -67,5 +68,5 @@ func (a *actionAddMember) Start(ctx context.Context) (bool, error) {
6768

6869
// ActionPlanAppender appends wait methods to the plan
6970
func (a *actionAddMember) ActionPlanAppender(current api.Plan) (api.Plan, bool) {
70-
return withWaitForMember(current, a.action.Group, withPredefinedMember(a.action.MemberID)), true
71+
return withWaitForMember(current, a.action.Group, shared.WithPredefinedMember(a.action.MemberID)), true
7172
}

pkg/deployment/reconcile/action_set_condition_v2.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,18 +26,7 @@ import (
2626
core "k8s.io/api/core/v1"
2727

2828
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
29-
)
30-
31-
const (
32-
setConditionActionV2KeyTypeAdd string = "add"
33-
setConditionActionV2KeyTypeRemove string = "remove"
34-
35-
setConditionActionV2KeyType string = "type"
36-
setConditionActionV2KeyAction string = "action"
37-
setConditionActionV2KeyStatus string = "status"
38-
setConditionActionV2KeyReason string = "reason"
39-
setConditionActionV2KeyMessage string = "message"
40-
setConditionActionV2KeyHash string = "hash"
29+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
4130
)
4231

4332
func newSetConditionV2Action(action api.Action, actionCtx ActionContext) Action {
@@ -57,32 +46,32 @@ type actionSetConditionV2 struct {
5746

5847
// Start starts the action for changing conditions on the provided member.
5948
func (a actionSetConditionV2) Start(ctx context.Context) (bool, error) {
60-
at, ok := a.action.Params[setConditionActionV2KeyType]
49+
at, ok := a.action.Params[shared.SetConditionActionV2KeyType]
6150
if !ok {
62-
a.log.Info("key %s is missing in action definition", setConditionActionV2KeyType)
51+
a.log.Info("key %s is missing in action definition", shared.SetConditionActionV2KeyType)
6352
return true, nil
6453
}
6554

66-
aa, ok := a.action.Params[setConditionActionV2KeyAction]
55+
aa, ok := a.action.Params[shared.SetConditionActionV2KeyAction]
6756
if !ok {
68-
a.log.Info("key %s is missing in action definition", setConditionActionV2KeyAction)
57+
a.log.Info("key %s is missing in action definition", shared.SetConditionActionV2KeyAction)
6958
return true, nil
7059
}
7160

7261
switch at {
73-
case setConditionActionV2KeyTypeAdd:
74-
ah := a.action.Params[setConditionActionV2KeyHash]
75-
am := a.action.Params[setConditionActionV2KeyMessage]
76-
ar := a.action.Params[setConditionActionV2KeyReason]
77-
as := a.action.Params[setConditionActionV2KeyStatus] == string(core.ConditionTrue)
62+
case shared.SetConditionActionV2KeyTypeAdd:
63+
ah := a.action.Params[shared.SetConditionActionV2KeyHash]
64+
am := a.action.Params[shared.SetConditionActionV2KeyMessage]
65+
ar := a.action.Params[shared.SetConditionActionV2KeyReason]
66+
as := a.action.Params[shared.SetConditionActionV2KeyStatus] == string(core.ConditionTrue)
7867

7968
if err := a.actionCtx.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
8069
return s.Conditions.UpdateWithHash(api.ConditionType(aa), as, ar, am, ah), nil
8170
}); err != nil {
8271
a.log.Err(err).Warn("unable to update status")
8372
return true, nil
8473
}
85-
case setConditionActionV2KeyTypeRemove:
74+
case shared.SetConditionActionV2KeyTypeRemove:
8675
if err := a.actionCtx.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
8776
return s.Conditions.Remove(api.ConditionType(aa)), nil
8877
}); err != nil {

pkg/deployment/reconcile/action_set_member_condition_v2.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import (
2626
core "k8s.io/api/core/v1"
2727

2828
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
29+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
2930
)
3031

3132
func newSetMemberConditionV2Action(action api.Action, actionCtx ActionContext) Action {
@@ -45,24 +46,24 @@ type actionSetMemberConditionV2 struct {
4546

4647
// Start starts the action for changing conditions on the provided member.
4748
func (a actionSetMemberConditionV2) Start(ctx context.Context) (bool, error) {
48-
at, ok := a.action.Params[setConditionActionV2KeyType]
49+
at, ok := a.action.Params[shared.SetConditionActionV2KeyType]
4950
if !ok {
50-
a.log.Info("key %s is missing in action definition", setConditionActionV2KeyType)
51+
a.log.Info("key %s is missing in action definition", shared.SetConditionActionV2KeyType)
5152
return true, nil
5253
}
5354

54-
aa, ok := a.action.Params[setConditionActionV2KeyAction]
55+
aa, ok := a.action.Params[shared.SetConditionActionV2KeyAction]
5556
if !ok {
56-
a.log.Info("key %s is missing in action definition", setConditionActionV2KeyAction)
57+
a.log.Info("key %s is missing in action definition", shared.SetConditionActionV2KeyAction)
5758
return true, nil
5859
}
5960

6061
switch at {
61-
case setConditionActionV2KeyTypeAdd:
62-
ah := a.action.Params[setConditionActionV2KeyHash]
63-
am := a.action.Params[setConditionActionV2KeyMessage]
64-
ar := a.action.Params[setConditionActionV2KeyReason]
65-
as := a.action.Params[setConditionActionV2KeyStatus] == string(core.ConditionTrue)
62+
case shared.SetConditionActionV2KeyTypeAdd:
63+
ah := a.action.Params[shared.SetConditionActionV2KeyHash]
64+
am := a.action.Params[shared.SetConditionActionV2KeyMessage]
65+
ar := a.action.Params[shared.SetConditionActionV2KeyReason]
66+
as := a.action.Params[shared.SetConditionActionV2KeyStatus] == string(core.ConditionTrue)
6667

6768
if err := a.actionCtx.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
6869
status, g, ok := s.Members.ElementByID(a.action.MemberID)
@@ -89,7 +90,7 @@ func (a actionSetMemberConditionV2) Start(ctx context.Context) (bool, error) {
8990
a.log.Err(err).Warn("unable to update status")
9091
return true, nil
9192
}
92-
case setConditionActionV2KeyTypeRemove:
93+
case shared.SetConditionActionV2KeyTypeRemove:
9394
if err := a.actionCtx.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
9495
status, g, ok := s.Members.ElementByID(a.action.MemberID)
9596
if !ok {

pkg/deployment/reconcile/condition_member_recreation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
3232
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
33+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
3334
"github.com/arangodb/kube-arangodb/pkg/util"
3435
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3536
)
@@ -47,12 +48,12 @@ func (r *Reconciler) createMemberRecreationConditionsPlan(ctx context.Context,
4748
if !recreate {
4849
if _, ok := m.Member.Conditions.Get(api.MemberReplacementRequired); ok {
4950
// Unset condition
50-
p = append(p, removeMemberConditionActionV2("Member replacement not required", api.MemberReplacementRequired, m.Group, m.Member.ID))
51+
p = append(p, shared.RemoveMemberConditionActionV2("Member replacement not required", api.MemberReplacementRequired, m.Group, m.Member.ID))
5152
}
5253
} else {
5354
if c, ok := m.Member.Conditions.Get(api.MemberReplacementRequired); !ok || !c.IsTrue() || c.Message != message {
5455
// Update condition
55-
p = append(p, updateMemberConditionActionV2("Member replacement required", api.MemberReplacementRequired, m.Group, m.Member.ID, true, "Member replacement required", message, ""))
56+
p = append(p, shared.UpdateMemberConditionActionV2("Member replacement required", api.MemberReplacementRequired, m.Group, m.Member.ID, true, "Member replacement required", message, ""))
5657
}
5758
}
5859
}

pkg/deployment/reconcile/plan_builder_clean_out.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import (
2525

2626
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2727
"github.com/arangodb/kube-arangodb/pkg/deployment/agency"
28+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
2829
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2930
)
3031

@@ -50,9 +51,9 @@ func (r *Reconciler) createCleanOutPlan(ctx context.Context, _ k8sutil.APIObject
5051

5152
if cleanedStatus != cleanedAgency {
5253
if cleanedAgency {
53-
plan = append(plan, updateMemberConditionActionV2("DBServer cleaned", api.ConditionTypeCleanedOut, m.Group, m.Member.ID, true, "DBServer cleaned", "DBServer cleaned", ""))
54+
plan = append(plan, shared.UpdateMemberConditionActionV2("DBServer cleaned", api.ConditionTypeCleanedOut, m.Group, m.Member.ID, true, "DBServer cleaned", "DBServer cleaned", ""))
5455
} else {
55-
plan = append(plan, removeMemberConditionActionV2("DBServer is not cleaned", api.ConditionTypeCleanedOut, m.Group, m.Member.ID))
56+
plan = append(plan, shared.RemoveMemberConditionActionV2("DBServer is not cleaned", api.ConditionTypeCleanedOut, m.Group, m.Member.ID))
5657
}
5758
}
5859
}

pkg/deployment/reconcile/plan_builder_cluster.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import (
2828

2929
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3030
"github.com/arangodb/kube-arangodb/pkg/deployment/actions"
31+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
3132
"github.com/arangodb/kube-arangodb/pkg/util/globals"
3233
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3334
)
@@ -82,7 +83,7 @@ func (r *Reconciler) createClusterOperationPlan(ctx context.Context, apiObject k
8283

8384
if member.LastHeartbeatAcked.Add(coordinatorHealthFailedTimeout).Before(time.Now()) {
8485
return api.Plan{
85-
actions.NewAction(api.ActionTypeClusterMemberCleanup, api.ServerGroupCoordinators, withPredefinedMember(string(id))),
86+
actions.NewAction(api.ActionTypeClusterMemberCleanup, api.ServerGroupCoordinators, shared.WithPredefinedMember(string(id))),
8687
}
8788
}
8889
case driver.ServerRoleDBServer:
@@ -95,7 +96,7 @@ func (r *Reconciler) createClusterOperationPlan(ctx context.Context, apiObject k
9596
}
9697

9798
return api.Plan{
98-
actions.NewAction(api.ActionTypeClusterMemberCleanup, api.ServerGroupDBServers, withPredefinedMember(string(id))),
99+
actions.NewAction(api.ActionTypeClusterMemberCleanup, api.ServerGroupDBServers, shared.WithPredefinedMember(string(id))),
99100
}
100101
}
101102
}

0 commit comments

Comments
 (0)