Skip to content

Commit 8bfabc0

Browse files
authored
[Feature] Member Update helpers (#1122)
1 parent 8371758 commit 8bfabc0

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
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
- (Feature) Define Actions PlaceHolder
5+
- (Feature) Add Member Update helpers
56

67
## [1.2.17](https://github.com/arangodb/kube-arangodb/tree/1.2.17) (2022-09-22)
78
- (Feature) Add new field to DeploymentReplicationStatus with details on DC2DC sync status=

pkg/deployment/context_impl.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,37 @@ func (d *Deployment) CreateOperatorEngineOpsAlertEvent(message string, args ...i
662662

663663
d.CreateEvent(k8sutil.NewOperatorEngineOpsAlertEvent(fmt.Sprintf(message, args...), d.GetAPIObject()))
664664
}
665+
666+
func (d *Deployment) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
667+
return d.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
668+
m, g, ok := s.Members.ElementByID(id)
669+
if !ok {
670+
return false, errors.Newf("Member %s not found", id)
671+
}
672+
673+
if g != group {
674+
return false, errors.Newf("Invalid group for %s. Wanted %s, found %s", id, group.AsRole(), g.AsRole())
675+
}
676+
677+
changed, err := action(&m)
678+
if err != nil {
679+
return false, err
680+
}
681+
682+
if !changed {
683+
return false, nil
684+
}
685+
686+
if err := s.Members.Update(m, g); err != nil {
687+
return false, err
688+
}
689+
690+
return true, nil
691+
})
692+
}
693+
694+
func (d *Deployment) WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateFunc) error {
695+
return d.WithMemberStatusUpdateErr(ctx, id, group, func(s *api.MemberStatus) (bool, error) {
696+
return action(s), nil
697+
})
698+
}

pkg/deployment/reconcile/action_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ type actionContext struct {
131131
metrics *Metrics
132132
}
133133

134+
func (ac *actionContext) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
135+
return ac.context.WithMemberStatusUpdateErr(ctx, id, group, action)
136+
}
137+
138+
func (ac *actionContext) WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateFunc) error {
139+
return ac.context.WithMemberStatusUpdate(ctx, id, group, action)
140+
}
141+
134142
func (ac *actionContext) CreateOperatorEngineOpsAlertEvent(message string, args ...interface{}) {
135143
ac.context.CreateOperatorEngineOpsAlertEvent(message, args...)
136144
}

pkg/deployment/reconcile/plan_builder_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ type testContext struct {
8686
state member.StateInspector
8787
}
8888

89+
func (c *testContext) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
90+
//TODO implement me
91+
panic("implement me")
92+
}
93+
94+
func (c *testContext) WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateFunc) error {
95+
//TODO implement me
96+
panic("implement me")
97+
}
98+
8999
func (c *testContext) CreateOperatorEngineOpsAlertEvent(message string, args ...interface{}) {
90100
//TODO implement me
91101
panic("implement me")

pkg/deployment/reconciler/context.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ type ServerGroupIterator interface {
4747

4848
type DeploymentStatusUpdateErrFunc func(s *api.DeploymentStatus) (bool, error)
4949
type DeploymentStatusUpdateFunc func(s *api.DeploymentStatus) bool
50+
type DeploymentMemberStatusUpdateErrFunc func(s *api.MemberStatus) (bool, error)
51+
type DeploymentMemberStatusUpdateFunc func(s *api.MemberStatus) bool
5052

5153
type DeploymentStatusUpdate interface {
5254
// WithStatusUpdateErr update status of ArangoDeployment with defined modifier. If action returns True action is taken
5355
WithStatusUpdateErr(ctx context.Context, action DeploymentStatusUpdateErrFunc) error
5456
// WithStatusUpdate update status of ArangoDeployment with defined modifier. If action returns True action is taken
5557
WithStatusUpdate(ctx context.Context, action DeploymentStatusUpdateFunc) error
5658

59+
// WithMemberStatusUpdateErr update status of ArangoDeployment Member with defined modifier. If action returns True action is taken
60+
WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action DeploymentMemberStatusUpdateErrFunc) error
61+
// WithMemberStatusUpdate update status of ArangoDeployment Member with defined modifier. If action returns True action is taken
62+
WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action DeploymentMemberStatusUpdateFunc) error
63+
5764
// UpdateStatus replaces the status of the deployment with the given status and
5865
// updates the resources in k8s.
5966
UpdateStatus(ctx context.Context, status api.DeploymentStatus) error

0 commit comments

Comments
 (0)