Skip to content

Commit 58b2ff9

Browse files
authored
[Cleanup] Reorganize main reconciliation context (#901)
1 parent 0350466 commit 58b2ff9

File tree

16 files changed

+330
-280
lines changed

16 files changed

+330
-280
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Define MemberReplacementRequired condition
77
- Remove pod immediately when annotation is turned on
88
- (ARM64) Add support for ARM64 enablement
9+
- (Cleanup) Reorganize main reconciliation context
910

1011
## [1.2.7](https://github.com/arangodb/kube-arangodb/tree/1.2.7) (2022-01-17)
1112
- Add Plan BackOff functionality

pkg/deployment/client/client_cache.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import (
2626
"strconv"
2727
"sync"
2828

29-
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
30-
3129
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3230

3331
"github.com/arangodb/go-driver/agency"
@@ -36,6 +34,7 @@ import (
3634

3735
driver "github.com/arangodb/go-driver"
3836
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
37+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
3938
)
4039

4140
type Cache interface {
@@ -49,8 +48,8 @@ type Cache interface {
4948
}
5049

5150
type CacheGen interface {
52-
resources.DeploymentEndpoints
53-
resources.DeploymentInfoGetter
51+
reconciler.DeploymentEndpoints
52+
reconciler.DeploymentInfoGetter
5453
}
5554

5655
func NewClientCache(in CacheGen, factory conn.Factory) Cache {

pkg/deployment/context_impl.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import (
7676

7777
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
7878
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
79+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
7980
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
8081
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
8182
core "k8s.io/api/core/v1"
@@ -97,7 +98,7 @@ func (d *Deployment) GetAPIObject() k8sutil.APIObject {
9798
}
9899

99100
// GetServerGroupIterator returns the deployment as ServerGroupIterator.
100-
func (d *Deployment) GetServerGroupIterator() resources.ServerGroupIterator {
101+
func (d *Deployment) GetServerGroupIterator() reconciler.ServerGroupIterator {
101102
return d.apiObject
102103
}
103104

@@ -226,8 +227,13 @@ func (d *Deployment) GetAuthentication() conn.Auth {
226227
}
227228

228229
// GetAgencyClients returns a client connection for every agency member.
230+
func (d *Deployment) GetAgencyClients(ctx context.Context) ([]driver.Connection, error) {
231+
return d.GetAgencyClientsWithPredicate(ctx, nil)
232+
}
233+
234+
// GetAgencyClientsWithPredicate returns a client connection for every agency member.
229235
// If the given predicate is not nil, only agents are included where the given predicate returns true.
230-
func (d *Deployment) GetAgencyClients(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {
236+
func (d *Deployment) GetAgencyClientsWithPredicate(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {
231237
agencyMembers := d.status.last.Members.Agents
232238
result := make([]driver.Connection, 0, len(agencyMembers))
233239
for _, m := range agencyMembers {
@@ -591,7 +597,7 @@ func (d *Deployment) GetArangoImage() string {
591597
return d.config.ArangoImage
592598
}
593599

594-
func (d *Deployment) WithStatusUpdateErr(ctx context.Context, action resources.DeploymentStatusUpdateErrFunc, force ...bool) error {
600+
func (d *Deployment) WithStatusUpdateErr(ctx context.Context, action reconciler.DeploymentStatusUpdateErrFunc, force ...bool) error {
595601
d.status.mutex.Lock()
596602
defer d.status.mutex.Unlock()
597603

@@ -610,7 +616,7 @@ func (d *Deployment) WithStatusUpdateErr(ctx context.Context, action resources.D
610616
return d.updateStatus(ctx, status, version, force...)
611617
}
612618

613-
func (d *Deployment) WithStatusUpdate(ctx context.Context, action resources.DeploymentStatusUpdateFunc, force ...bool) error {
619+
func (d *Deployment) WithStatusUpdate(ctx context.Context, action reconciler.DeploymentStatusUpdateFunc, force ...bool) error {
614620
return d.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
615621
return action(s), nil
616622
}, force...)
@@ -680,7 +686,7 @@ func (d *Deployment) SetCachedStatus(i inspectorInterface.Inspector) {
680686
d.currentState = i
681687
}
682688

683-
func (d *Deployment) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberUpdateFunc) error {
689+
func (d *Deployment) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberUpdateFunc) error {
684690
o, err := d.deps.DatabaseCRCli.DatabaseV1().ArangoMembers(namespace).Get(ctx, name, meta.GetOptions{})
685691
if err != nil {
686692
return err
@@ -695,7 +701,7 @@ func (d *Deployment) WithArangoMemberUpdate(ctx context.Context, namespace, name
695701
return nil
696702
}
697703

698-
func (d *Deployment) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberStatusUpdateFunc) error {
704+
func (d *Deployment) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberStatusUpdateFunc) error {
699705
o, err := d.deps.DatabaseCRCli.DatabaseV1().ArangoMembers(namespace).Get(ctx, name, meta.GetOptions{})
700706
if err != nil {
701707
return err

pkg/deployment/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (d *Deployment) RefreshAgencyCache(ctx context.Context) (uint64, error) {
164164
}
165165

166166
func (d *Deployment) SetAgencyMaintenanceMode(ctx context.Context, enabled bool) error {
167-
if !d.Mode().HasAgents() {
167+
if !d.GetMode().HasAgents() {
168168
return nil
169169
}
170170

pkg/deployment/reconcile/action_context.go

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import (
2929
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3030

3131
"github.com/arangodb/arangosync-client/client"
32-
"github.com/arangodb/go-driver"
3332
"github.com/arangodb/go-driver/agency"
3433

34+
"github.com/arangodb/go-driver"
3535
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
3636
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3737
agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency"
38-
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
38+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
3939
"github.com/arangodb/kube-arangodb/pkg/util/errors"
4040
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
4141
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
@@ -52,31 +52,17 @@ import (
5252
// ActionContext provides methods to the Action implementations
5353
// to control their context.
5454
type ActionContext interface {
55-
resources.DeploymentStatusUpdate
56-
resources.DeploymentAgencyMaintenance
57-
resources.ArangoMemberContext
58-
resources.DeploymentPodRenderer
59-
resources.DeploymentModInterfaces
60-
resources.DeploymentCachedStatus
61-
resources.ArangoAgencyGet
62-
resources.DeploymentInfoGetter
63-
64-
// Gets the specified mode of deployment
65-
GetMode() api.DeploymentMode
66-
// GetDatabaseClient returns a cached client for the entire database (cluster coordinators or single server),
67-
// creating one if needed.
68-
GetDatabaseClient(ctx context.Context) (driver.Client, error)
69-
// GetServerClient returns a cached client for a specific server.
70-
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
71-
// GetAgencyClients returns a client connection for every agency member.
72-
GetAgencyClients(ctx context.Context) ([]driver.Connection, error)
73-
// GetAgency returns a connection to the entire agency.
74-
GetAgency(ctx context.Context) (agency.Agency, error)
75-
// GetSyncServerClient returns a cached client for a specific arangosync server.
76-
GetSyncServerClient(ctx context.Context, group api.ServerGroup, id string) (client.API, error)
77-
// CreateEvent creates a given event.
78-
// On error, the error is logged.
79-
CreateEvent(evt *k8sutil.Event)
55+
reconciler.DeploymentStatusUpdate
56+
reconciler.DeploymentAgencyMaintenance
57+
reconciler.ArangoMemberContext
58+
reconciler.DeploymentPodRenderer
59+
reconciler.DeploymentModInterfaces
60+
reconciler.DeploymentCachedStatus
61+
reconciler.ArangoAgencyGet
62+
reconciler.DeploymentInfoGetter
63+
reconciler.DeploymentClient
64+
reconciler.DeploymentSyncClient
65+
8066
// GetMemberStatusByID returns the current member status
8167
// for the member with given id.
8268
// Returns member status, true when found, or false
@@ -119,7 +105,7 @@ type ActionContext interface {
119105
// GetImageInfo returns the image info for an image with given name.
120106
// Returns: (info, infoFound)
121107
GetImageInfo(imageName string) (api.ImageInfo, bool)
122-
// GetImageInfo returns the image info for an current image.
108+
// GetCurrentImageInfo returns the image info for an current image.
123109
// Returns: (info, infoFound)
124110
GetCurrentImageInfo() (api.ImageInfo, bool)
125111
// SetCurrentImage changes the CurrentImage field in the deployment
@@ -135,7 +121,7 @@ type ActionContext interface {
135121
DisableScalingCluster(ctx context.Context) error
136122
// EnableScalingCluster enables scaling DBservers and coordinators
137123
EnableScalingCluster(ctx context.Context) error
138-
// WithStatusUpdate update status of ArangoDeployment with defined modifier. If action returns True action is taken
124+
// UpdateClusterCondition update status of ArangoDeployment with defined modifier. If action returns True action is taken
139125
UpdateClusterCondition(ctx context.Context, conditionType api.ConditionType, status bool, reason, message string) error
140126
// GetBackup receives information about a backup resource
141127
GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error)
@@ -161,6 +147,18 @@ type actionContext struct {
161147
cachedStatus inspectorInterface.Inspector
162148
}
163149

150+
func (ac *actionContext) UpdateStatus(ctx context.Context, status api.DeploymentStatus, lastVersion int32, force ...bool) error {
151+
return ac.context.UpdateStatus(ctx, status, lastVersion, force...)
152+
}
153+
154+
func (ac *actionContext) GetNamespace() string {
155+
return ac.context.GetNamespace()
156+
}
157+
158+
func (ac *actionContext) GetAgencyClientsWithPredicate(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {
159+
return ac.context.GetAgencyClientsWithPredicate(ctx, predicate)
160+
}
161+
164162
func (ac *actionContext) GetStatus() (api.DeploymentStatus, int32) {
165163
return ac.context.GetStatus()
166164
}
@@ -189,11 +187,11 @@ func (ac *actionContext) SetAgencyMaintenanceMode(ctx context.Context, enabled b
189187
return ac.context.SetAgencyMaintenanceMode(ctx, enabled)
190188
}
191189

192-
func (ac *actionContext) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberUpdateFunc) error {
190+
func (ac *actionContext) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberUpdateFunc) error {
193191
return ac.context.WithArangoMemberUpdate(ctx, namespace, name, action)
194192
}
195193

196-
func (ac *actionContext) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberStatusUpdateFunc) error {
194+
func (ac *actionContext) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberStatusUpdateFunc) error {
197195
return ac.context.WithArangoMemberStatusUpdate(ctx, namespace, name, action)
198196
}
199197

@@ -221,11 +219,11 @@ func (ac *actionContext) GetBackup(ctx context.Context, backup string) (*backupA
221219
return ac.context.GetBackup(ctx, backup)
222220
}
223221

224-
func (ac *actionContext) WithStatusUpdateErr(ctx context.Context, action resources.DeploymentStatusUpdateErrFunc, force ...bool) error {
222+
func (ac *actionContext) WithStatusUpdateErr(ctx context.Context, action reconciler.DeploymentStatusUpdateErrFunc, force ...bool) error {
225223
return ac.context.WithStatusUpdateErr(ctx, action, force...)
226224
}
227225

228-
func (ac *actionContext) WithStatusUpdate(ctx context.Context, action resources.DeploymentStatusUpdateFunc, force ...bool) error {
226+
func (ac *actionContext) WithStatusUpdate(ctx context.Context, action reconciler.DeploymentStatusUpdateFunc, force ...bool) error {
229227
return ac.context.WithStatusUpdate(ctx, action, force...)
230228
}
231229

@@ -322,7 +320,7 @@ func (ac *actionContext) GetServerClient(ctx context.Context, group api.ServerGr
322320

323321
// GetAgencyClients returns a client connection for every agency member.
324322
func (ac *actionContext) GetAgencyClients(ctx context.Context) ([]driver.Connection, error) {
325-
c, err := ac.context.GetAgencyClients(ctx, nil)
323+
c, err := ac.context.GetAgencyClients(ctx)
326324
if err != nil {
327325
return nil, errors.WithStack(err)
328326
}

pkg/deployment/reconcile/context.go

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,54 +23,34 @@ package reconcile
2323
import (
2424
"context"
2525

26-
"github.com/arangodb/arangosync-client/client"
27-
"github.com/arangodb/go-driver"
28-
"github.com/arangodb/go-driver/agency"
2926
v1 "k8s.io/api/core/v1"
3027
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3128

29+
"github.com/arangodb/go-driver"
3230
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
3331
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
34-
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
32+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
3533
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
36-
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3734
)
3835

3936
type CreateMemberMod func(s *api.DeploymentStatus, g api.ServerGroup, m *api.MemberStatus) error
4037

4138
// Context provides methods to the reconcile package.
4239
type Context interface {
43-
resources.DeploymentStatusUpdate
44-
resources.DeploymentAgencyMaintenance
45-
resources.ArangoMemberContext
46-
resources.DeploymentPodRenderer
47-
resources.DeploymentImageManager
48-
resources.DeploymentModInterfaces
49-
resources.DeploymentCachedStatus
50-
resources.ArangoAgencyGet
51-
resources.ArangoApplier
52-
resources.DeploymentInfoGetter
40+
reconciler.DeploymentStatusUpdate
41+
reconciler.DeploymentAgencyMaintenance
42+
reconciler.ArangoMemberContext
43+
reconciler.DeploymentPodRenderer
44+
reconciler.DeploymentImageManager
45+
reconciler.DeploymentModInterfaces
46+
reconciler.DeploymentCachedStatus
47+
reconciler.ArangoAgencyGet
48+
reconciler.ArangoApplier
49+
reconciler.DeploymentInfoGetter
50+
reconciler.DeploymentClient
51+
reconciler.KubernetesEventGenerator
52+
reconciler.DeploymentSyncClient
5353

54-
// UpdateStatus replaces the status of the deployment with the given status and
55-
// updates the resources in k8s.
56-
UpdateStatus(ctx context.Context, status api.DeploymentStatus, lastVersion int32, force ...bool) error
57-
// UpdateMember updates the deployment status wrt the given member.
58-
UpdateMember(ctx context.Context, member api.MemberStatus) error
59-
// GetDatabaseClient returns a cached client for the entire database (cluster coordinators or single server),
60-
// creating one if needed.
61-
GetDatabaseClient(ctx context.Context) (driver.Client, error)
62-
// GetServerClient returns a cached client for a specific server.
63-
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
64-
// GetAgencyClients returns a client connection for every agency member.
65-
// If the given predicate is not nil, only agents are included where the given predicate returns true.
66-
GetAgencyClients(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error)
67-
// GetAgency returns a connection to the entire agency.
68-
GetAgency(ctx context.Context) (agency.Agency, error)
69-
// GetSyncServerClient returns a cached client for a specific arangosync server.
70-
GetSyncServerClient(ctx context.Context, group api.ServerGroup, id string) (client.API, error)
71-
// CreateEvent creates a given event.
72-
// On error, the error is logged.
73-
CreateEvent(evt *k8sutil.Event)
7454
// CreateMember adds a new member to the given group.
7555
// If ID is non-empty, it will be used, otherwise a new ID is created.
7656
// Returns ID, error
@@ -112,8 +92,6 @@ type Context interface {
11292
EnableScalingCluster(ctx context.Context) error
11393
// GetBackup receives information about a backup resource
11494
GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error)
115-
// GetName receives deployment name
116-
GetName() string
11795
// GetAuthentication return authentication for members
11896
GetAuthentication() conn.Auth
11997
}

pkg/deployment/reconcile/plan_builder_context.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,41 @@ package reconcile
2323
import (
2424
"context"
2525

26-
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
27-
28-
"github.com/arangodb/go-driver/agency"
2926
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
3027

3128
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
3229

33-
"github.com/arangodb/go-driver"
34-
3530
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
36-
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
31+
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
3732
core "k8s.io/api/core/v1"
3833
)
3934

4035
// PlanBuilderContext contains context methods provided to plan builders.
4136
type PlanBuilderContext interface {
42-
resources.DeploymentAgencyMaintenance
43-
resources.ArangoMemberContext
44-
resources.DeploymentPodRenderer
45-
resources.DeploymentImageManager
46-
resources.DeploymentModInterfaces
47-
resources.DeploymentCachedStatus
48-
resources.ArangoAgencyGet
37+
reconciler.DeploymentInfoGetter
38+
reconciler.DeploymentAgencyMaintenance
39+
reconciler.ArangoMemberContext
40+
reconciler.DeploymentPodRenderer
41+
reconciler.DeploymentImageManager
42+
reconciler.DeploymentModInterfaces
43+
reconciler.DeploymentCachedStatus
44+
reconciler.ArangoAgencyGet
45+
reconciler.DeploymentClient
46+
reconciler.KubernetesEventGenerator
4947

5048
// GetTLSKeyfile returns the keyfile encoded TLS certificate+key for
5149
// the given member.
5250
GetTLSKeyfile(group api.ServerGroup, member api.MemberStatus) (string, error)
53-
// CreateEvent creates a given event.
54-
// On error, the error is logged.
55-
CreateEvent(evt *k8sutil.Event)
5651
// GetPvc gets a PVC by the given name, in the samespace of the deployment.
5752
GetPvc(ctx context.Context, pvcName string) (*core.PersistentVolumeClaim, error)
5853
// GetShardSyncStatus returns true if all shards are in sync
5954
GetShardSyncStatus() bool
6055
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
6156
InvalidateSyncStatus()
62-
// GetStatus returns the current status of the deployment
63-
GetStatus() (api.DeploymentStatus, int32)
64-
// GetStatus returns the current spec of the deployment
65-
GetSpec() api.DeploymentSpec
66-
// GetDatabaseClient returns a cached client for the entire database (cluster coordinators or single server),
67-
// creating one if needed.
68-
GetDatabaseClient(ctx context.Context) (driver.Client, error)
69-
// GetServerClient returns a cached client for a specific server.
70-
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
7157
// GetAuthentication return authentication for members
7258
GetAuthentication() conn.Auth
7359
// GetBackup receives information about a backup resource
7460
GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error)
75-
// GetName receives deployment name
76-
GetName() string
77-
// GetAgency returns a connection to the entire agency.
78-
GetAgency(ctx context.Context) (agency.Agency, error)
7961
}
8062

8163
// newPlanBuilderContext creates a PlanBuilderContext from the given context

0 commit comments

Comments
 (0)