Skip to content

Commit b5e707e

Browse files
authored
[Feature] License V2 for ArangoDB 3.9.0+ (#870)
1 parent 591acec commit b5e707e

19 files changed

+779
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Keep only recent terminations
88
- Add endpoint into member status
99
- Add debug mode (Golang DLV)
10+
- License V2 for ArangoDB 3.9.0+
1011

1112
## [1.2.6](https://github.com/arangodb/kube-arangodb/tree/1.2.6) (2021-12-15)
1213
- Add ArangoBackup backoff functionality

pkg/apis/deployment/v1/conditions.go

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const (
8484

8585
// ConditionTypeTopologyAware indicates that the member is deployed with TopologyAwareness.
8686
ConditionTypeTopologyAware ConditionType = "TopologyAware"
87+
88+
// ConditionTypeLicenseSet indicates that license V2 is set on cluster.
89+
ConditionTypeLicenseSet ConditionType = "LicenseSet"
8790
)
8891

8992
// Condition represents one current condition of a deployment or deployment member.
@@ -102,6 +105,8 @@ type Condition struct {
102105
Reason string `json:"reason,omitempty"`
103106
// A human readable message indicating details about the transition.
104107
Message string `json:"message,omitempty"`
108+
// Hash keep propagation hash id, for example checksum of secret
109+
Hash string `json:"hash,omitempty"`
105110
}
106111

107112
func (c Condition) IsTrue() bool {
@@ -139,7 +144,8 @@ func (c Condition) Equal(other Condition) bool {
139144
util.TimeCompareEqual(c.LastUpdateTime, other.LastUpdateTime) &&
140145
util.TimeCompareEqual(c.LastTransitionTime, other.LastTransitionTime) &&
141146
c.Reason == other.Reason &&
142-
c.Message == other.Message
147+
c.Message == other.Message &&
148+
c.Hash == other.Hash
143149
}
144150

145151
// IsTrue return true when a condition with given type exists and its status is `True`.
@@ -178,47 +184,72 @@ func (list *ConditionList) Touch(conditionType ConditionType) bool {
178184
return false
179185
}
180186

181-
// Update the condition, replacing an old condition with same type (if any)
182-
// Returns true when changes were made, false otherwise.
183-
func (list *ConditionList) Update(conditionType ConditionType, status bool, reason, message string) bool {
187+
func (list ConditionList) Index(conditionType ConditionType) int {
188+
for i, x := range list {
189+
if x.Type == conditionType {
190+
return i
191+
}
192+
}
193+
194+
return -1
195+
}
196+
197+
func (list *ConditionList) update(conditionType ConditionType, status bool, reason, message, hash string) bool {
184198
src := *list
185199
statusX := v1.ConditionFalse
186200
if status {
187201
statusX = v1.ConditionTrue
188202
}
189-
for i, x := range src {
190-
if x.Type == conditionType {
191-
if x.Status != statusX {
192-
// Transition to another status
193-
src[i].Status = statusX
194-
now := metav1.Now()
195-
src[i].LastTransitionTime = now
196-
src[i].LastUpdateTime = now
197-
src[i].Reason = reason
198-
src[i].Message = message
199-
} else if x.Reason != reason || x.Message != message {
200-
src[i].LastUpdateTime = metav1.Now()
201-
src[i].Reason = reason
202-
src[i].Message = message
203-
} else {
204-
return false
205-
}
206-
return true
207-
}
203+
204+
index := list.Index(conditionType)
205+
206+
if index == -1 {
207+
// Not found
208+
now := metav1.Now()
209+
*list = append(src, Condition{
210+
Type: conditionType,
211+
LastUpdateTime: now,
212+
LastTransitionTime: now,
213+
Status: statusX,
214+
Reason: reason,
215+
Message: message,
216+
Hash: hash,
217+
})
218+
return true
219+
}
220+
221+
if src[index].Status != statusX {
222+
// Transition to another status
223+
src[index].Status = statusX
224+
now := metav1.Now()
225+
src[index].LastTransitionTime = now
226+
src[index].LastUpdateTime = now
227+
src[index].Reason = reason
228+
src[index].Message = message
229+
src[index].Hash = hash
230+
} else if src[index].Reason != reason || src[index].Message != message || src[index].Hash != hash {
231+
src[index].LastUpdateTime = metav1.Now()
232+
src[index].Reason = reason
233+
src[index].Message = message
234+
src[index].Hash = hash
235+
} else {
236+
return false
208237
}
209-
// Not found
210-
now := metav1.Now()
211-
*list = append(src, Condition{
212-
Type: conditionType,
213-
LastUpdateTime: now,
214-
LastTransitionTime: now,
215-
Status: statusX,
216-
Reason: reason,
217-
Message: message,
218-
})
219238
return true
220239
}
221240

241+
// Update the condition, replacing an old condition with same type (if any)
242+
// Returns true when changes were made, false otherwise.
243+
func (list *ConditionList) Update(conditionType ConditionType, status bool, reason, message string) bool {
244+
return list.update(conditionType, status, reason, message, "")
245+
}
246+
247+
// UpdateWithHash updates the condition, replacing an old condition with same type (if any)
248+
// Returns true when changes were made, false otherwise.
249+
func (list *ConditionList) UpdateWithHash(conditionType ConditionType, status bool, reason, message, hash string) bool {
250+
return list.update(conditionType, status, reason, message, hash)
251+
}
252+
222253
// Remove the condition with given type.
223254
// Returns true if removed, or false if not found.
224255
func (list *ConditionList) Remove(conditionType ConditionType) bool {

pkg/apis/deployment/v1/plan.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (a ActionType) String() string {
4949
// Priority returns plan priority
5050
func (a ActionType) Priority() ActionPriority {
5151
switch a {
52-
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition, ActionTypeSetCondition:
52+
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition, ActionTypeSetCondition, ActionTypeSetMemberConditionV2:
5353
return ActionPriorityHigh
5454
default:
5555
return ActionPriorityNormal
@@ -161,8 +161,12 @@ const (
161161
ActionTypeMemberPhaseUpdate ActionType = "MemberPhaseUpdate"
162162
// ActionTypeSetMemberCondition sets member condition. It is high priority action.
163163
ActionTypeSetMemberCondition ActionType = "SetMemberCondition"
164+
// ActionTypeSetMemberConditionV2 sets member condition. It is high priority action.
165+
ActionTypeSetMemberConditionV2 ActionType = "SetMemberConditionV2"
164166
// ActionTypeSetCondition sets condition. It is high priority action.
165167
ActionTypeSetCondition ActionType = "SetCondition"
168+
// ActionTypeSetConditionV2 sets condition. It is high priority action.
169+
ActionTypeSetConditionV2 ActionType = "SetConditionV2"
166170
// ActionTypeMemberRIDUpdate updated member Run ID (UID). High priority
167171
ActionTypeMemberRIDUpdate ActionType = "MemberRIDUpdate"
168172
// ActionTypeArangoMemberUpdatePodSpec updates pod spec

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const (
8484

8585
// ConditionTypeTopologyAware indicates that the member is deployed with TopologyAwareness.
8686
ConditionTypeTopologyAware ConditionType = "TopologyAware"
87+
88+
// ConditionTypeLicenseSet indicates that license V2 is set on cluster.
89+
ConditionTypeLicenseSet ConditionType = "LicenseSet"
8790
)
8891

8992
// Condition represents one current condition of a deployment or deployment member.
@@ -102,6 +105,8 @@ type Condition struct {
102105
Reason string `json:"reason,omitempty"`
103106
// A human readable message indicating details about the transition.
104107
Message string `json:"message,omitempty"`
108+
// Hash keep propagation hash id, for example checksum of secret
109+
Hash string `json:"hash,omitempty"`
105110
}
106111

107112
func (c Condition) IsTrue() bool {
@@ -139,7 +144,8 @@ func (c Condition) Equal(other Condition) bool {
139144
util.TimeCompareEqual(c.LastUpdateTime, other.LastUpdateTime) &&
140145
util.TimeCompareEqual(c.LastTransitionTime, other.LastTransitionTime) &&
141146
c.Reason == other.Reason &&
142-
c.Message == other.Message
147+
c.Message == other.Message &&
148+
c.Hash == other.Hash
143149
}
144150

145151
// IsTrue return true when a condition with given type exists and its status is `True`.
@@ -178,47 +184,72 @@ func (list *ConditionList) Touch(conditionType ConditionType) bool {
178184
return false
179185
}
180186

181-
// Update the condition, replacing an old condition with same type (if any)
182-
// Returns true when changes were made, false otherwise.
183-
func (list *ConditionList) Update(conditionType ConditionType, status bool, reason, message string) bool {
187+
func (list ConditionList) Index(conditionType ConditionType) int {
188+
for i, x := range list {
189+
if x.Type == conditionType {
190+
return i
191+
}
192+
}
193+
194+
return -1
195+
}
196+
197+
func (list *ConditionList) update(conditionType ConditionType, status bool, reason, message, hash string) bool {
184198
src := *list
185199
statusX := v1.ConditionFalse
186200
if status {
187201
statusX = v1.ConditionTrue
188202
}
189-
for i, x := range src {
190-
if x.Type == conditionType {
191-
if x.Status != statusX {
192-
// Transition to another status
193-
src[i].Status = statusX
194-
now := metav1.Now()
195-
src[i].LastTransitionTime = now
196-
src[i].LastUpdateTime = now
197-
src[i].Reason = reason
198-
src[i].Message = message
199-
} else if x.Reason != reason || x.Message != message {
200-
src[i].LastUpdateTime = metav1.Now()
201-
src[i].Reason = reason
202-
src[i].Message = message
203-
} else {
204-
return false
205-
}
206-
return true
207-
}
203+
204+
index := list.Index(conditionType)
205+
206+
if index == -1 {
207+
// Not found
208+
now := metav1.Now()
209+
*list = append(src, Condition{
210+
Type: conditionType,
211+
LastUpdateTime: now,
212+
LastTransitionTime: now,
213+
Status: statusX,
214+
Reason: reason,
215+
Message: message,
216+
Hash: hash,
217+
})
218+
return true
219+
}
220+
221+
if src[index].Status != statusX {
222+
// Transition to another status
223+
src[index].Status = statusX
224+
now := metav1.Now()
225+
src[index].LastTransitionTime = now
226+
src[index].LastUpdateTime = now
227+
src[index].Reason = reason
228+
src[index].Message = message
229+
src[index].Hash = hash
230+
} else if src[index].Reason != reason || src[index].Message != message || src[index].Hash != hash {
231+
src[index].LastUpdateTime = metav1.Now()
232+
src[index].Reason = reason
233+
src[index].Message = message
234+
src[index].Hash = hash
235+
} else {
236+
return false
208237
}
209-
// Not found
210-
now := metav1.Now()
211-
*list = append(src, Condition{
212-
Type: conditionType,
213-
LastUpdateTime: now,
214-
LastTransitionTime: now,
215-
Status: statusX,
216-
Reason: reason,
217-
Message: message,
218-
})
219238
return true
220239
}
221240

241+
// Update the condition, replacing an old condition with same type (if any)
242+
// Returns true when changes were made, false otherwise.
243+
func (list *ConditionList) Update(conditionType ConditionType, status bool, reason, message string) bool {
244+
return list.update(conditionType, status, reason, message, "")
245+
}
246+
247+
// UpdateWithHash updates the condition, replacing an old condition with same type (if any)
248+
// Returns true when changes were made, false otherwise.
249+
func (list *ConditionList) UpdateWithHash(conditionType ConditionType, status bool, reason, message, hash string) bool {
250+
return list.update(conditionType, status, reason, message, hash)
251+
}
252+
222253
// Remove the condition with given type.
223254
// Returns true if removed, or false if not found.
224255
func (list *ConditionList) Remove(conditionType ConditionType) bool {

pkg/apis/deployment/v2alpha1/plan.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (a ActionType) String() string {
4949
// Priority returns plan priority
5050
func (a ActionType) Priority() ActionPriority {
5151
switch a {
52-
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition, ActionTypeSetCondition:
52+
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition, ActionTypeSetCondition, ActionTypeSetMemberConditionV2:
5353
return ActionPriorityHigh
5454
default:
5555
return ActionPriorityNormal
@@ -161,8 +161,12 @@ const (
161161
ActionTypeMemberPhaseUpdate ActionType = "MemberPhaseUpdate"
162162
// ActionTypeSetMemberCondition sets member condition. It is high priority action.
163163
ActionTypeSetMemberCondition ActionType = "SetMemberCondition"
164+
// ActionTypeSetMemberConditionV2 sets member condition. It is high priority action.
165+
ActionTypeSetMemberConditionV2 ActionType = "SetMemberConditionV2"
164166
// ActionTypeSetCondition sets condition. It is high priority action.
165167
ActionTypeSetCondition ActionType = "SetCondition"
168+
// ActionTypeSetConditionV2 sets condition. It is high priority action.
169+
ActionTypeSetConditionV2 ActionType = "SetConditionV2"
166170
// ActionTypeMemberRIDUpdate updated member Run ID (UID). High priority
167171
ActionTypeMemberRIDUpdate ActionType = "MemberRIDUpdate"
168172
// ActionTypeArangoMemberUpdatePodSpec updates pod spec

pkg/deployment/client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func NewClient(c driver.Connection) Client {
3636
}
3737

3838
type Client interface {
39+
LicenseClient
40+
3941
GetTLS(ctx context.Context) (TLSDetails, error)
4042
RefreshTLS(ctx context.Context) (TLSDetails, error)
4143

0 commit comments

Comments
 (0)