8000 [Bugfix] Improve Wait Procedure on AF (#1834) · arangodb/kube-arangodb@4353b2b · GitHub
[go: up one dir, main page]

Skip to content

Commit 4353b2b

Browse files
authored
[Bugfix] Improve Wait Procedure on AF (#1834)
1 parent 8226121 commit 4353b2b

File tree

11 files changed

+98
-63
lines changed

11 files changed

+98
-63
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
- (Bugfix) Use Profile Annotations
5+
- (Bugfix) Improve Wait Procedure on AF
56

67
## [1.2.46](https://github.com/arangodb/kube-arangodb/tree/1.2.46) (2025-02-24)
78
- (Bugfix) Clean Phase change properly during upgrade

pkg/apis/deployment/v1/plan.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -314,31 +314,7 @@ func (p Plan) Wrap(before, after Action) Plan {
314314

315315
// AfterFirst adds actions when condition will return false
316316
func (p Plan) AfterFirst(condition func(a Action) bool, actions ...Action) Plan {
317-
var r Plan
318-
c := p
319-
for {
320-
if len(c) == 0 {
321-
break
322-
}
323-
324-
if !condition(c[0]) {
325-
r = append(r, actions...)
326-
327-
r = append(r, c...)
328-
329-
break
330-
}
331-
332-
r = append(r, c[0])
333-
334-
if len(c) == 1 {
335-
break
336-
}
337-
338-
c = c[1:]
339 6D47 -
}
340-
341-
return r
317+
return util.AppendAfter(p, condition, actions...)
342318
}
343319

344320
// Filter filter list of the actions

pkg/apis/deployment/v1/plan_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -87,3 +87,16 @@ func Test_Action_Equal(t *testing.T) {
8787
require.False(t, b.Equal(a))
8888
require.True(t, b.Equal(b))
8989
}
90+
91+
func Test_Plan_AfterFirst(t *testing.T) {
92+
var p Plan
93+
94+
require.Len(t, p, 0)
95+
96+
p = p.AfterFirst(func(a Action) bool {
97+
return false
98+
}, Action{ID: "1", Type: ActionTypeAddMember})
99+
100+
require.Len(t, p, 1)
101+
require.Equal(t, "1", p[0].ID)
102+
}

pkg/apis/deployment/v2alpha1/plan.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -314,31 +314,7 @@ func (p Plan) Wrap(before, after Action) Plan {
314314

315315
// AfterFirst adds actions when condition will return false
316316
func (p Plan) AfterFirst(condition func(a Action) bool, actions ...Action) Plan {
317-
var r Plan
318-
c := p
319-
for {
320-
if len(c) == 0 {
321-
break
322-
}
323-
324-
if !condition(c[0]) {
325-
r = append(r, actions...)
326-
327-
r = append(r, c...)
328-
329-
break
330-
}
331-
332-
r = append(r, c[0])
333-
334-
if len(c) == 1 {
335-
break
336-
}
337-
338-
c = c[1:]
339-
}
340-
341-
return r
317+
return util.AppendAfter(p, condition, actions...)
342318
}
343319

344320
// Filter filter list of the actions

pkg/apis/deployment/v2alpha1/plan_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -87,3 +87,16 @@ func Test_Action_Equal(t *testing.T) {
8787
require.False(t, b.Equal(a))
8888
require.True(t, b.Equal(b))
8989
}
90+
91+
func Test_Plan_AfterFirst(t *testing.T) {
92+
var p Plan
93+
94+
require.Len(t, p, 0)
95+
96+
p = p.AfterFirst(func(a Action) bool {
97+
return false
98+
}, Action{ID: "1", Type: ActionTypeAddMember})
99+
100+
require.Len(t, p, 1)
101+
require.Equal(t, "1", p[0].ID)
102+
}

pkg/apis/shared/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.

pkg/deployment/reconcile/plan_builder_rotate_upgrade.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (r *Reconciler) createUpdatePlanInternal(apiObject k8sutil.APIObject, spec
232232
sharedReconcile.UpdateMemberConditionActionV2(reason, api.ConditionTypeUpdating, m.Group, m.Member.ID, true, reason, "", ""),
233233
}, false
234234
} else {
235-
p = withWaitForMember(p, m.Group, m.Member)
235+
p = append(p, waitForMemberActions(m.Group, m.Member)...)
236236

237237
p = append(p, actions.NewAction(api.ActionTypeArangoMemberUpdatePodStatus, m.Group, m.Member, "Propagating status of pod").AddParam(ActionTypeArangoMemberUpdatePodStatusChecksum, checksum))
238238
p = p.WrapWithPlan(api.Plan{
@@ -622,7 +622,7 @@ func skipResignLeadership(mode api.DeploymentMode, v driver.Version) bool {
622622

623623
func withWaitForMember(plan api.Plan, group api.ServerGroup, member api.MemberStatus) api.Plan {
624624
return plan.AfterFirst(func(a api.Action) bool {
625-
return a.Type == api.ActionTypeAddMember
625+
return a.Type != api.ActionTypeAddMember
626626
}, waitForMemberActions(group, member)...)
627627

628628
}

pkg/deployment/reconcile/plan_builder_storage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -175,14 +175,14 @@ func (r *Reconciler) pvcResizePlan(group api.ServerGroup, member api.MemberStatu
175175
actions.NewAction(api.ActionTypePVCResize, group, member),
176176
}
177177
case api.PVCResizeModeRotate:
178-
return withWaitForMember(api.Plan{
178+
return util.FlattenLists(api.Plan{
179179
actions.NewAction(getResignLeadershipActionType(), group, member),
180180
actions.NewAction(api.ActionTypeKillMemberPod, group, member),
181181
actions.NewAction(api.ActionTypeRotateStartMember, group, member),
182182
actions.NewAction(api.ActionTypePVCResize, group, member),
183183
actions.NewAction(api.ActionTypePVCResized, group, member),
184184
actions.NewAction(api.ActionTypeRotateStopMember, group, member),
185-
}, group, member)
185+
}, waitForMemberActions(group, member))
186186
default:
187187
r.planLogger.Str("server-group", group.AsRole()).Str("mode", mode.String()).
188188
Error("Requested mode is not supported")

pkg/deployment/reconcile/plan_builder_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -56,7 +56,7 @@ func createRotateMemberPlanWithAction(member api.MemberStatus,
5656
actions.NewAction(api.ActionTypeCleanMemberService, group, member, "Remove server service and enforce renewal/recreation"),
5757
)
5858

59-
plan = withWaitForMember(plan, group, member)
59+
plan = append(plan, waitForMemberActions(group, member)...)
6060

6161
plan = withMemberMaintenance(group, member, "Enable member maintenance", plan)
6262

pkg/util/list.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,35 @@ func FlattenList[A any](in [][]A) []A {
195195
func FlattenLists[A any](in ...[]A) []A {
196196
return FlattenList(in)
197197
}
198+
199+
func AppendAfter[T any](in []T, condition func(v T) bool, elements ...T) []T {
200+
for id := range in {
201+
if condition(in[id]) {
202+
if id == len(in)-1 {
203+
break
204+
}
205+
206+
// We need to merge results
207+
208+
z := make([]T, len(in)+len(elements))
209+
210+
q := z
211+
212+
copy(q, in[:id+1])
213+
q = q[id+1:]
214+
215+
copy(q, elements)
216+
217+
q = q[len(elements):]
218+
219+
copy(q, in[id+1:])
220+
221+
return z
222+
}
223+
}
224+
225+
z := make([]T, len(in)+len(elements))
226+
copy(z, in)
227+
copy(z[len(in):], elements)
228+
return z
229+
}

pkg/util/list_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 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.
@@ -67,3 +67,27 @@ func Test_MapList(t *testing.T) {
6767
return o.name
6868
}))
6969
}
70+
71+
func Test_AppendAfter(t *testing.T) {
72+
var elements []int
73+
74+
elements = AppendAfter(elements, func(v int) bool {
75+
return false
76+
}, 1)
77+
require.Equal(t, []int{1}, elements)
78+
79+
elements = AppendAfter(elements, func(v int) bool {
80+
return false
81+
}, 2)
82+
require.Equal(t, []int{1, 2}, elements)
83+
84+
elements = AppendAfter(elements, func(v int) bool {
85+
return v == 1
86+
}, 3)
87+
require.Equal(t, []int{1, 3, 2}, elements)
88+
89+
elements = AppendAfter(elements, func(v int) bool {
90+
return v == 2
91+
}, 4)
92+
require.Equal(t, []int{1, 3, 2, 4}, elements)
93+
}

0 commit comments

Comments
 (0)
0