Skip to content

Commit 8c465a8

Browse files
authored
[Feature] Propagate member conditions (#1382)
1 parent 282a50e commit 8c465a8

13 files changed

+537
-6
lines changed

docs/generated/actions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
| MarkToRemoveMember | no | 10m0s | no | Community & Enterprise | Marks member to be removed. Used when member Pod is annotated with replace annotation |
4242
| MemberPhaseUpdate | no | 10m0s | no | Community & Enterprise | Change member phase |
4343
| ~~MemberRIDUpdate~~ | no | 10m0s | no | Community & Enterprise | Update Run ID of member |
44+
| MemberStatusSync | no | 10m0s | no | Community & Enterprise | Sync ArangoMember Status with ArangoDeployment Status, to keep Member information up to date |
4445
| PVCResize | no | 30m0s | no | Community & Enterprise | Start the resize procedure. Updates PVC Requests field |
4546
| PVCResized | no | 15m0s | no | Community & Enterprise | Waits for PVC resize to be completed |
4647
| PlaceHolder | no | 10m0s | no | Community & Enterprise | Empty placeholder action |
@@ -133,6 +134,7 @@ spec:
133134
MarkToRemoveMember: 10m0s
134135
MemberPhaseUpdate: 10m0s
135136
MemberRIDUpdate: 10m0s
137+
MemberStatusSync: 10m0s
136138
PVCResize: 30m0s
137139
PVCResized: 15m0s
138140
PlaceHolder: 10m0s

internal/actions.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ actions:
177177
description: Change member phase
178178
scopes:
179179
- High
180+
MemberStatusSync:
181+
description: Sync ArangoMember Status with ArangoDeployment Status, to keep Member information up to date
182+
scopes:
183+
- High
180184
SetMemberCondition:
181185
description: Set member condition
182186
scopes:

pkg/apis/deployment/v1/actions.generated.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ const (
134134
// ActionMemberRIDUpdateDefaultTimeout define default timeout for action ActionMemberRIDUpdate
135135
ActionMemberRIDUpdateDefaultTimeout time.Duration = ActionsDefaultTimeout
136136

137+
// ActionMemberStatusSyncDefaultTimeout define default timeout for action ActionMemberStatusSync
138+
ActionMemberStatusSyncDefaultTimeout time.Duration = ActionsDefaultTimeout
139+
137140
// ActionPVCResizeDefaultTimeout define default timeout for action ActionPVCResize
138141
ActionPVCResizeDefaultTimeout time.Duration = 1800 * time.Second // 30m0s
139142

@@ -388,6 +391,9 @@ const (
388391
// Deprecated: action is not used anymore
389392
ActionTypeMemberRIDUpdate ActionType = "MemberRIDUpdate"
390393

394+
// ActionTypeMemberStatusSync in scopes High. Sync ArangoMember Status with ArangoDeployment Status, to keep Member information up to date
395+
ActionTypeMemberStatusSync ActionType = "MemberStatusSync"
396+
391397
// ActionTypePVCResize in scopes Normal. Start the resize procedure. Updates PVC Requests field
392398
ActionTypePVCResize ActionType = "PVCResize"
393399

@@ -605,6 +611,8 @@ func (a ActionType) DefaultTimeout() time.Duration {
605611
return ActionMemberPhaseUpdateDefaultTimeout
606612
case ActionTypeMemberRIDUpdate:
607613
return ActionMemberRIDUpdateDefaultTimeout
614+
case ActionTypeMemberStatusSync:
615+
return ActionMemberStatusSyncDefaultTimeout
608616
case ActionTypePVCResize:
609617
return ActionPVCResizeDefaultTimeout
610618
case ActionTypePVCResized:
@@ -777,6 +785,8 @@ func (a ActionType) Priority() ActionPriority {
777785
return ActionPriorityHigh
778786
case ActionTypeMemberRIDUpdate:
779787
return ActionPriorityHigh
788+
case ActionTypeMemberStatusSync:
789+
return ActionPriorityHigh
780790
case ActionTypePVCResize:
781791
return ActionPriorityNormal
782792
case ActionTypePVCResized:
@@ -961,6 +971,8 @@ func (a ActionType) Optional() bool {
961971
return false
962972
case ActionTypeMemberRIDUpdate:
963973
return false
974+
case ActionTypeMemberStatusSync:
975+
return false
964976
case ActionTypePVCResize:
965977
return false
966978
case ActionTypePVCResized:

pkg/apis/deployment/v1/arango_member_status.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-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 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.
@@ -25,3 +25,16 @@ type ArangoMemberStatus struct {
2525

2626
Template *ArangoMemberPodTemplate `json:"template,omitempty"`
2727
}
28+
29+
func (a ArangoMemberStatus) InSync(status MemberStatus) bool {
30+
return status.Conditions.Equal(a.Conditions)
31+
}
32+
33+
func (a *ArangoMemberStatus) Propagate(status MemberStatus) (changed bool) {
34+
if !status.Conditions.Equal(a.Conditions) {
35+
changed = true
36+
a.Conditions = status.Conditions.DeepCopy()
37+
}
38+
39+
return
40+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1
22+
23+
import (
24+
"testing"
25+
26+
"github.com/stretchr/testify/require"
27+
core "k8s.io/api/core/v1"
28+
)
29+
30+
func Test_ArangoMemberStatus_Propagate(t *testing.T) {
31+
var status ArangoMemberStatus
32+
33+
t.Run("Add first condition", func(t *testing.T) {
34+
var member = MemberStatus{
35+
Conditions: ConditionList{
36+
{
37+
Type: ConditionTypeScheduled,
38+
Status: core.ConditionTrue,
39+
},
40+
},
41+
}
42+
43+
require.False(t, status.InSync(member))
44+
require.True(t, status.Propagate(member))
45+
require.True(t, status.InSync(member))
46+
require.False(t, status.Propagate(member))
47+
48+
require.Equal(t, member.Conditions, status.Conditions)
49+
})
50+
51+
t.Run("Update first condition", func(t *testing.T) {
52+
var member = MemberStatus{
53+
Conditions: ConditionList{
54+
{
55+
Type: ConditionTypeScheduled,
56+
Status: core.ConditionFalse,
57+
},
58+
},
59+
}
60+
61+
require.NotEqual(t, member.Conditions, status.Conditions)
62+
63+
require.False(t, status.InSync(member))
64+
require.True(t, status.Propagate(member))
65+
require.True(t, status.InSync(member))
66+
require.False(t, status.Propagate(member))
67+
68+
require.Equal(t, member.Conditions, status.Conditions)
69+
})
70+
}

0 commit comments

Comments
 (0)