Skip to content

Commit 65bbce5

Browse files
authored
[Feature] [ACS] Unify client handler (#987)
1 parent d56e3f9 commit 65bbce5

File tree

72 files changed

+640
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+640
-587
lines changed

pkg/deployment/acs/acs.community.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,31 @@ type acs struct {
4343
cache inspectorInterface.Inspector
4444
}
4545

46+
func (a acs) ForEachHealthyCluster(f func(item sutil.ACSItem) error) error {
47+
return f(a)
48+
}
49+
50+
func (a acs) CurrentClusterCache() inspectorInterface.Inspector {
51+
return a.cache
52+
}
53+
54+
func (a acs) ClusterCache(uid types.UID) (inspectorInterface.Inspector, bool) {
55+
c, ok := a.Cluster(uid)
56+
if ok {
57+
return c.Cache(), true
58+
}
59+
60+
return nil, false
61+
}
62+
4663
func (a acs) UID() types.UID {
4764
return a.main
4865
}
4966

67+
func (a acs) Ready() bool {
68+
return true
69+
}
70+
5071
func (a acs) Cache() inspectorInterface.Inspector {
5172
return a.cache
5273
}

pkg/deployment/acs/sutil/interfaces.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ import (
2929
"k8s.io/apimachinery/pkg/types"
3030
)
3131

32+
type ACSGetter interface {
33+
ACS() ACS
34+
}
35+
3236
type ACS interface {
3337
ACSItem
3438

3539
Inspect(ctx context.Context, deployment *api.ArangoDeployment, client kclient.Client, cachedStatus inspectorInterface.Inspector) error
3640

3741
Cluster(uid types.UID) (ACSItem, bool)
42+
CurrentClusterCache() inspectorInterface.Inspector
43+
ClusterCache(uid types.UID) (inspectorInterface.Inspector, bool)
44+
45+
ForEachHealthyCluster(f func(item ACSItem) error) error
3846

3947
RemoteClusters() []types.UID
4048
}
4149

4250
type ACSItem interface {
4351
UID() types.UID
4452
Cache() inspectorInterface.Inspector
53+
Ready() bool
4554
}

pkg/deployment/context_impl.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import (
5858
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
5959
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
6060
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
61+
"github.com/arangodb/kube-arangodb/pkg/deployment/acs/sutil"
6162
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
6263
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
6364
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
@@ -567,20 +568,20 @@ func (d *Deployment) GetAgencyData(ctx context.Context, i interface{}, keyParts
567568
return err
568569
}
569570

570-
func (d *Deployment) RenderPodForMember(ctx context.Context, cachedStatus inspectorInterface.Inspector, spec api.DeploymentSpec, status api.DeploymentStatus, memberID string, imageInfo api.ImageInfo) (*core.Pod, error) {
571-
return d.resources.RenderPodForMember(ctx, cachedStatus, spec, status, memberID, imageInfo)
571+
func (d *Deployment) RenderPodForMember(ctx context.Context, acs sutil.ACS, spec api.DeploymentSpec, status api.DeploymentStatus, memberID string, imageInfo api.ImageInfo) (*core.Pod, error) {
572+
return d.resources.RenderPodForMember(ctx, acs, spec, status, memberID, imageInfo)
572573
}
573574

574-
func (d *Deployment) RenderPodForMemberFromCurrent(ctx context.Context, cachedStatus inspectorInterface.Inspector, memberID string) (*core.Pod, error) {
575-
return d.resources.RenderPodForMemberFromCurrent(ctx, cachedStatus, memberID)
575+
func (d *Deployment) RenderPodForMemberFromCurrent(ctx context.Context, acs sutil.ACS, memberID string) (*core.Pod, error) {
576+
return d.resources.RenderPodForMemberFromCurrent(ctx, acs, memberID)
576577
}
577578

578-
func (d *Deployment) RenderPodTemplateForMember(ctx context.Context, cachedStatus inspectorInterface.Inspector, spec api.DeploymentSpec, status api.DeploymentStatus, memberID string, imageInfo api.ImageInfo) (*core.PodTemplateSpec, error) {
579-
return d.resources.RenderPodTemplateForMember(ctx, cachedStatus, spec, status, memberID, imageInfo)
579+
func (d *Deployment) RenderPodTemplateForMember(ctx context.Context, acs sutil.ACS, spec api.DeploymentSpec, status api.DeploymentStatus, memberID string, imageInfo api.ImageInfo) (*core.PodTemplateSpec, error) {
580+
return d.resources.RenderPodTemplateForMember(ctx, acs, spec, status, memberID, imageInfo)
580581
}
581582

582-
func (d *Deployment) RenderPodTemplateForMemberFromCurrent(ctx context.Context, cachedStatus inspectorInterface.Inspector, memberID string) (*core.PodTemplateSpec, error) {
583-
return d.resources.RenderPodTemplateForMemberFromCurrent(ctx, cachedStatus, memberID)
583+
func (d *Deployment) RenderPodTemplateForMemberFromCurrent(ctx context.Context, acs sutil.ACS, memberID string) (*core.PodTemplateSpec, error) {
584+
return d.resources.RenderPodTemplateForMemberFromCurrent(ctx, acs, memberID)
584585
}
585586

586587
func (d *Deployment) SelectImage(spec api.DeploymentSpec, status api.DeploymentStatus) (api.ImageInfo, bool) {
@@ -710,3 +711,7 @@ func (d *Deployment) GetStatusSnapshot() api.DeploymentStatus {
710711

711712
return *z
712713
}
714+
715+
func (d *Deployment) ACS() sutil.ACS {
716+
return d.acs
717+
}

pkg/deployment/deployment_inspector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
182182
}
183183

184184
// Cleanup terminated pods on the beginning of loop
185-
if x, err := d.resources.CleanupTerminatedPods(ctx, d.GetCachedStatus()); err != nil {
185+
if x, err := d.resources.CleanupTerminatedPods(ctx); err != nil {
186186
return minInspectionInterval, errors.Wrapf(err, "Pod cleanup failed")
187187
} else {
188188
nextInterval = nextInterval.ReduceTo(x)
@@ -346,7 +346,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
346346
}
347347

348348
// At the end of the inspect, we cleanup terminated pods.
349-
if x, err := d.resources.CleanupTerminatedPods(ctx, d.GetCachedStatus()); err != nil {
349+
if x, err := d.resources.CleanupTerminatedPods(ctx); err != nil {
350350
return minInspectionInterval, errors.Wrapf(err, "Pod cleanup failed")
351351
} else {
352352
nextInterval = nextInterval.ReduceTo(x)

pkg/deployment/deployment_run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func runTestCase(t *testing.T, testCase testCaseStruct) {
179179
image, ok := d.resources.SelectImage(d.apiObject.Spec, d.status.last)
180180
require.True(t, ok)
181181

182-
template, err := d.resources.RenderPodTemplateForMember(context.Background(), d.GetCachedStatus(), d.apiObject.Spec, d.status.last, m.ID, image)
182+
template, err := d.resources.RenderPodTemplateForMember(context.Background(), d.ACS(), d.apiObject.Spec, d.status.last, m.ID, image)
183183
if err != nil {
184184
return err
185185
}

pkg/deployment/deployment_suite_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343

4444
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
4545
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
46+
"github.com/arangodb/kube-arangodb/pkg/deployment/acs"
4647
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
4748
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
4849
arangofake "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/fake"
@@ -490,6 +491,7 @@ func createTestDeployment(t *testing.T, config Config, arangoDeployment *api.Ara
490491
currentState: inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), deps.Client, arangoDeployment.GetNamespace(), arangoDeployment.GetName()),
491492
}
492493
d.clientCache = client.NewClientCache(d, conn.NewFactory(d.getAuth, d.getConnConfig))
494+
d.acs = acs.NewACS("", d.currentState)
493495

494496
require.NoError(t, d.currentState.Refresh(context.Background()))
495497

pkg/deployment/reconcile/action.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import (
3030

3131
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3232
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
33+
"k8s.io/apimachinery/pkg/types"
34+
)
35+
36+
const (
37+
DefaultStartFailureGracePeriod = 10 * time.Second
3338
)
3439

3540
func GetAllActions() []api.ActionType {
@@ -82,12 +87,12 @@ type ActionReloadCachedStatus interface {
8287
Action
8388

8489
// ReloadComponents return cache components to be reloaded
85-
ReloadComponents() []throttle.Component
90+
ReloadComponents() (types.UID, []throttle.Component)
8691
}
8792

88-
func getActionReloadCachedStatus(a Action) []throttle.Component {
93+
func getActionReloadCachedStatus(a Action) (types.UID, []throttle.Component) {
8994
if c, ok := a.(ActionReloadCachedStatus); !ok {
90-
return nil
95+
return "", nil
9196
} else {
9297
return c.ReloadComponents()
9398
}
@@ -127,7 +132,7 @@ func (a actionStartFailureGracePeriod) StartFailureGracePeriod() time.Duration {
127132

128133
func getStartFailureGracePeriod(a Action) time.Duration {
129134
if c, ok := a.(ActionStartFailureGracePeriod); !ok {
130-
return 0
135+
return DefaultStartFailureGracePeriod
131136
} else {
132137
return c.StartFailureGracePeriod()
133138
}

pkg/deployment/reconcile/action_arango_member_update_pod_spec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro
6868
return true, nil
6969
}
7070

71-
member, ok := a.actionCtx.GetCachedStatus().ArangoMember().V1().GetSimple(m.ArangoMemberName(a.actionCtx.GetName(), a.action.Group))
71+
member, ok := a.actionCtx.ACS().CurrentClusterCache().ArangoMember().V1().GetSimple(m.ArangoMemberName(a.actionCtx.GetName(), a.action.Group))
7272
if !ok {
7373
err := errors.Newf("ArangoMember not found")
7474
log.Error().Err(err).Msg("ArangoMember not found")
@@ -102,7 +102,7 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro
102102
imageInfo = *m.Image
103103
}
104104

105-
renderedPod, err := a.actionCtx.RenderPodTemplateForMember(ctx, a.actionCtx.GetCachedStatus(), spec, status, a.action.MemberID, imageInfo)
105+
renderedPod, err := a.actionCtx.RenderPodTemplateForMember(ctx, a.actionCtx.ACS(), spec, status, a.action.MemberID, imageInfo)
106106
if err != nil {
107107
log.Err(err).Msg("Error while rendering pod")
108108
return false, err

pkg/deployment/reconcile/action_arango_member_update_pod_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (a *actionArangoMemberUpdatePodStatus) Start(ctx context.Context) (bool, er
6767
return true, nil
6868
}
6969

70-
member, ok := a.actionCtx.GetCachedStatus().ArangoMember().V1().GetSimple(m.ArangoMemberName(a.actionCtx.GetName(), a.action.Group))
70+
member, ok := a.actionCtx.ACS().CurrentClusterCache().ArangoMember().V1().GetSimple(m.ArangoMemberName(a.actionCtx.GetName(), a.action.Group))
7171
if !ok {
7272
err := errors.Newf("ArangoMember not found")
7373
log.Error().Err(err).Msg("ArangoMember not found")

pkg/deployment/reconcile/action_bootstrap_set_password.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (a actionBootstrapSetPassword) setUserPassword(ctx context.Context, user, s
138138
}
139139

140140
func (a actionBootstrapSetPassword) ensureUserPasswordSecret(ctx context.Context, user, secret string) (string, error) {
141-
if auth, ok := a.actionCtx.GetCachedStatus().Secret().V1().GetSimple(secret); !ok {
141+
if auth, ok := a.actionCtx.ACS().CurrentClusterCache().Secret().V1().GetSimple(secret); !ok {
142142
// Create new one
143143
tokenData := make([]byte, 32)
144144
if _, err := rand.Read(tokenData); err != nil {

0 commit comments

Comments
 (0)