1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Member Update helpers (#1122)

This commit is contained in:
Adam Janikowski 2022-09-26 10:30:22 +02:00 committed by GitHub
parent 837175813c
commit 8bfabc032a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 0 deletions

View file

@ -2,6 +2,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) Define Actions PlaceHolder
- (Feature) Add Member Update helpers
## [1.2.17](https://github.com/arangodb/kube-arangodb/tree/1.2.17) (2022-09-22)
- (Feature) Add new field to DeploymentReplicationStatus with details on DC2DC sync status=

View file

@ -662,3 +662,37 @@ func (d *Deployment) CreateOperatorEngineOpsAlertEvent(message string, args ...i
d.CreateEvent(k8sutil.NewOperatorEngineOpsAlertEvent(fmt.Sprintf(message, args...), d.GetAPIObject()))
}
func (d *Deployment) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
return d.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
m, g, ok := s.Members.ElementByID(id)
if !ok {
return false, errors.Newf("Member %s not found", id)
}
if g != group {
return false, errors.Newf("Invalid group for %s. Wanted %s, found %s", id, group.AsRole(), g.AsRole())
}
changed, err := action(&m)
if err != nil {
return false, err
}
if !changed {
return false, nil
}
if err := s.Members.Update(m, g); err != nil {
return false, err
}
return true, nil
})
}
func (d *Deployment) WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateFunc) error {
return d.WithMemberStatusUpdateErr(ctx, id, group, func(s *api.MemberStatus) (bool, error) {
return action(s), nil
})
}

View file

@ -131,6 +131,14 @@ type actionContext struct {
metrics *Metrics
}
func (ac *actionContext) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
return ac.context.WithMemberStatusUpdateErr(ctx, id, group, action)
}
func (ac *actionContext) WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateFunc) error {
return ac.context.WithMemberStatusUpdate(ctx, id, group, action)
}
func (ac *actionContext) CreateOperatorEngineOpsAlertEvent(message string, args ...interface{}) {
ac.context.CreateOperatorEngineOpsAlertEvent(message, args...)
}

View file

@ -86,6 +86,16 @@ type testContext struct {
state member.StateInspector
}
func (c *testContext) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
//TODO implement me
panic("implement me")
}
func (c *testContext) WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateFunc) error {
//TODO implement me
panic("implement me")
}
func (c *testContext) CreateOperatorEngineOpsAlertEvent(message string, args ...interface{}) {
//TODO implement me
panic("implement me")

View file

@ -47,6 +47,8 @@ type ServerGroupIterator interface {
type DeploymentStatusUpdateErrFunc func(s *api.DeploymentStatus) (bool, error)
type DeploymentStatusUpdateFunc func(s *api.DeploymentStatus) bool
type DeploymentMemberStatusUpdateErrFunc func(s *api.MemberStatus) (bool, error)
type DeploymentMemberStatusUpdateFunc func(s *api.MemberStatus) bool
type DeploymentStatusUpdate interface {
// WithStatusUpdateErr update status of ArangoDeployment with defined modifier. If action returns True action is taken
@ -54,6 +56,11 @@ type DeploymentStatusUpdate interface {
// WithStatusUpdate update status of ArangoDeployment with defined modifier. If action returns True action is taken
WithStatusUpdate(ctx context.Context, action DeploymentStatusUpdateFunc) error
// WithMemberStatusUpdateErr update status of ArangoDeployment Member with defined modifier. If action returns True action is taken
WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action DeploymentMemberStatusUpdateErrFunc) error
// WithMemberStatusUpdate update status of ArangoDeployment Member with defined modifier. If action returns True action is taken
WithMemberStatusUpdate(ctx context.Context, id string, group api.ServerGroup, action DeploymentMemberStatusUpdateFunc) error
// UpdateStatus replaces the status of the deployment with the given status and
// updates the resources in k8s.
UpdateStatus(ctx context.Context, status api.DeploymentStatus) error