Skip to content

Commit 2eb4ccc

Browse files
authored
[Feature] Add Pending Phase (#776)
1 parent ab9873d commit 2eb4ccc

19 files changed

+762
-356
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- Update 'github.com/arangodb/arangosync-client' dependency to v0.7.0
55
- Add HighPriorityPlan to ArangoDeployment Status
6+
- Add Pending Member phase
67

78
## [1.2.1](https://github.com/arangodb/kube-arangodb/tree/1.2.1) (2021-07-28)
89
- Fix ArangoMember race with multiple ArangoDeployments within single namespace

pkg/apis/deployment/v1/member_phase.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type MemberPhase string
2828
const (
2929
// MemberPhaseNone indicates that the state is not set yet
3030
MemberPhaseNone MemberPhase = ""
31+
// MemberPhasePending indicates that member propagation has been started
32+
MemberPhasePending MemberPhase = "Pending"
3133
// MemberPhaseCreated indicates that all resources needed for the member have been created
3234
MemberPhaseCreated MemberPhase = "Created"
3335
// MemberPhaseFailed indicates that the member is gone beyond hope of recovery. It must be replaced with a new member.
@@ -48,6 +50,11 @@ const (
4850
MemberPhaseUpgrading MemberPhase = "Upgrading"
4951
)
5052

53+
// IsPending returns true when given phase == "" OR "Pending"
54+
func (p MemberPhase) IsPending() bool {
55+
return p == MemberPhaseNone || p == MemberPhasePending
56+
}
57+
5158
// IsFailed returns true when given phase == "Failed"
5259
func (p MemberPhase) IsFailed() bool {
5360
return p == MemberPhaseFailed
@@ -62,3 +69,13 @@ func (p MemberPhase) IsCreatedOrDrain() bool {
6269
func (p MemberPhase) String() string {
6370
return string(p)
6471
}
72+
73+
// GetPhase parses string into phase
74+
func GetPhase(phase string) (MemberPhase, bool) {
75+
switch p := MemberPhase(phase); p {
76+
case MemberPhaseNone, MemberPhasePending, MemberPhaseCreated, MemberPhaseFailed, MemberPhaseCleanOut, MemberPhaseDrain, MemberPhaseResign, MemberPhaseShuttingDown, MemberPhaseRotating, MemberPhaseRotateStart, MemberPhaseUpgrading:
77+
return p, true
78+
default:
79+
return "", false
80+
}
81+
}

pkg/apis/deployment/v1/member_status.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type MemberStatus struct {
4141
// ID holds the unique ID of the member.
4242
// This id is also used within the ArangoDB cluster to identify this server.
4343
ID string `json:"id"`
44+
// RID holds the ID of the member run.
45+
// Value is updated in Pending Phase.
46+
RID types.UID `json:"rid,omitempty"`
4447
// Phase holds the current lifetime phase of this member
4548
Phase MemberPhase `json:"phase"`
4649
// CreatedAt holds the creation timestamp of this member.
@@ -82,6 +85,7 @@ type MemberStatus struct {
8285
// Equal checks for equality
8386
func (s MemberStatus) Equal(other MemberStatus) bool {
8487
return s.ID == other.ID &&
88+
s.RID == other.RID &&
8589
s.Phase == other.Phase &&
8690
util.TimeCompareEqual(s.CreatedAt, other.CreatedAt) &&
8791
s.PersistentVolumeClaimName == other.PersistentVolumeClaimName &&

pkg/apis/deployment/v1/member_status_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (l MemberStatusList) SelectMemberToRemove() (MemberStatus, error) {
151151
}
152152
// Try to find a not ready member
153153
for _, m := range l {
154-
if m.Phase == MemberPhaseNone {
154+
if m.Phase.IsPending() {
155155
return m, nil
156156
}
157157
}

pkg/apis/deployment/v1/plan.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func (a ActionType) String() string {
4949
// Priority returns plan priority
5050
func (a ActionType) Priority() ActionPriority {
5151
switch a {
52+
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate:
53+
return ActionPriorityHigh
5254
default:
5355
return ActionPriorityNormal
5456
}
@@ -153,6 +155,10 @@ const (
153155
ActionTypeBootstrapUpdate ActionType = "BootstrapUpdate"
154156
// ActionTypeBootstrapSetPassword set password to the bootstrapped user
155157
ActionTypeBootstrapSetPassword ActionType = "BootstrapSetPassword"
158+
// ActionTypeMemberPhaseUpdate updated member phase. High priority
159+
ActionTypeMemberPhaseUpdate ActionType = "MemberPhaseUpdate"
160+
// ActionTypeMemberRIDUpdate updated member Run ID (UID). High priority
161+
ActionTypeMemberRIDUpdate ActionType = "MemberRIDUpdate"
156162
)
157163

158164
const (

pkg/apis/deployment/v2alpha1/member_phase.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type MemberPhase string
2828
const (
2929
// MemberPhaseNone indicates that the state is not set yet
3030
MemberPhaseNone MemberPhase = ""
31+
// MemberPhasePending indicates that member propagation has been started
32+
MemberPhasePending MemberPhase = "Pending"
3133
// MemberPhaseCreated indicates that all resources needed for the member have been created
3234
MemberPhaseCreated MemberPhase = "Created"
3335
// MemberPhaseFailed indicates that the member is gone beyond hope of recovery. It must be replaced with a new member.
@@ -48,6 +50,11 @@ const (
4850
MemberPhaseUpgrading MemberPhase = "Upgrading"
4951
)
5052

53+
// IsPending returns true when given phase == "" OR "Pending"
54+
func (p MemberPhase) IsPending() bool {
55+
return p == MemberPhaseNone || p == MemberPhasePending
56+
}
57+
5158
// IsFailed returns true when given phase == "Failed"
5259
func (p MemberPhase) IsFailed() bool {
5360
return p == MemberPhaseFailed
@@ -62,3 +69,13 @@ func (p MemberPhase) IsCreatedOrDrain() bool {
6269
func (p MemberPhase) String() string {
6370
return string(p)
6471
}
72+
73+
// GetPhase parses string into phase
74+
func GetPhase(phase string) (MemberPhase, bool) {
75+
switch p := MemberPhase(phase); p {
76+
case MemberPhaseNone, MemberPhasePending, MemberPhaseCreated, MemberPhaseFailed, MemberPhaseCleanOut, MemberPhaseDrain, MemberPhaseResign, MemberPhaseShuttingDown, MemberPhaseRotating, MemberPhaseRotateStart, MemberPhaseUpgrading:
77+
return p, true
78+
default:
79+
return "", false
80+
}
81+
}

pkg/apis/deployment/v2alpha1/member_status.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type MemberStatus struct {
4141
// ID holds the unique ID of the member.
4242
// This id is also used within the ArangoDB cluster to identify this server.
4343
ID string `json:"id"`
44+
// RID holds the ID of the member run.
45+
// Value is updated in Pending Phase.
46+
RID types.UID `json:"rid,omitempty"`
4447
// Phase holds the current lifetime phase of this member
4548
Phase MemberPhase `json:"phase"`
4649
// CreatedAt holds the creation timestamp of this member.
@@ -82,6 +85,7 @@ type MemberStatus struct {
8285
// Equal checks for equality
8386
func (s MemberStatus) Equal(other MemberStatus) bool {
8487
return s.ID == other.ID &&
88+
s.RID == other.RID &&
8589
s.Phase == other.Phase &&
8690
util.TimeCompareEqual(s.CreatedAt, other.CreatedAt) &&
8791
s.PersistentVolumeClaimName == other.PersistentVolumeClaimName &&

pkg/apis/deployment/v2alpha1/member_status_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (l MemberStatusList) SelectMemberToRemove() (MemberStatus, error) {
151151
}
152152
// Try to find a not ready member
153153
for _, m := range l {
154-
if m.Phase == MemberPhaseNone {
154+
if m.Phase.IsPending() {
155155
return m, nil
156156
}
157157
}

pkg/apis/deployment/v2alpha1/plan.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func (a ActionType) String() string {
4949
// Priority returns plan priority
5050
func (a ActionType) Priority() ActionPriority {
5151
switch a {
52+
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate:
53+
return ActionPriorityHigh
5254
default:
5355
return ActionPriorityNormal
5456
}
@@ -153,6 +155,10 @@ const (
153155
ActionTypeBootstrapUpdate ActionType = "BootstrapUpdate"
154156
// ActionTypeBootstrapSetPassword set password to the bootstrapped user
155157
ActionTypeBootstrapSetPassword ActionType = "BootstrapSetPassword"
158+
// ActionTypeMemberPhaseUpdate updated member phase. High priority
159+
ActionTypeMemberPhaseUpdate ActionType = "MemberPhaseUpdate"
160+
// ActionTypeMemberRIDUpdate updated member Run ID (UID). High priority
161+
ActionTypeMemberRIDUpdate ActionType = "MemberRIDUpdate"
156162
)
157163

158164
const (

pkg/deployment/deployment_run_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ func runTestCase(t *testing.T, testCase testCaseStruct) {
9696
if testCase.Resources != nil {
9797
testCase.Resources(t, d)
9898
}
99+
// Set Pending phase
100+
require.NoError(t, d.status.last.Members.ForeachServerGroup(func(group api.ServerGroup, list api.MemberStatusList) error {
101+
for _, m := range list {
102+
if m.Phase == api.MemberPhaseNone {
103+
m.Phase = api.MemberPhasePending
104+
if err := d.status.last.Members.Update(m, group); err != nil {
105+
return err
106+
}
107+
}
108+
}
109+
return nil
110+
}))
99111

100112
// Set members
101113
require.NoError(t, d.status.last.Members.ForeachServerGroup(func(group api.ServerGroup, list api.MemberStatusList) error {

0 commit comments

Comments
 (0)