Skip to content

Commit 03a5659

Browse files
authored
[Feature] ScaleDown candidate (#1120)
1 parent 987cefe commit 03a5659

File tree

8 files changed

+66
-6
lines changed

8 files changed

+66
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- (Debug Package) Initial commit
99
- (Feature) Detach PVC from deployment in Ordered indexing method
1010
- (Feature) OPS Alerts
11+
- (Feature) ScaleDown Candidate
1112

1213
## [1.2.16](https://github.com/arangodb/kube-arangodb/tree/1.2.16) (2022-09-14)
1314
- (Feature) Add ArangoDeployment ServerGroupStatus

pkg/apis/deployment/annotations.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
package deployment
2222

2323
const (
24-
ArangoDeploymentAnnotationPrefix = "deployment.arangodb.com"
25-
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
26-
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
27-
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
28-
ArangoDeploymentPodDeleteNow = ArangoDeploymentAnnotationPrefix + "/delete_now"
29-
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
24+
ArangoDeploymentAnnotationPrefix = "deployment.arangodb.com"
25+
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
26+
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
27+
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
28+
ArangoDeploymentPodDeleteNow = ArangoDeploymentAnnotationPrefix + "/delete_now"
29+
ArangoDeploymentPodScaleDownCandidateAnnotation = ArangoDeploymentAnnotationPrefix + "/scale_down_candidate"
30+
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
3031
)

pkg/apis/deployment/v1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const (
6868
ConditionTypeSpecAccepted ConditionType = "SpecAccepted"
6969
// ConditionTypeMarkedToRemove indicates that the member is marked to be removed.
7070
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"
71+
// ConditionTypeScaleDownCandidate indicates that the member will be picked in ScaleDown operaion.
72+
ConditionTypeScaleDownCandidate ConditionType = "ScaleDownCandidate"
7173
// ConditionTypeUpgradeFailed indicates that upgrade failed
7274
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"
7375

pkg/apis/deployment/v1/member_status_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelect
149149
return m, nil
150150
}
151151
}
152+
for _, m := range l {
153+
if m.Conditions.IsTrue(ConditionTypeScaleDownCandidate) {
154+
return m, nil
155+
}
156+
}
152157
// Try to find a not ready member
153158
for _, m := range l {
154159
if m.Phase.IsPending() {

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const (
6868
ConditionTypeSpecAccepted ConditionType = "SpecAccepted"
6969
// ConditionTypeMarkedToRemove indicates that the member is marked to be removed.
7070
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"
71+
// ConditionTypeScaleDownCandidate indicates that the member will be picked in ScaleDown operaion.
72+
ConditionTypeScaleDownCandidate ConditionType = "ScaleDownCandidate"
7173
// ConditionTypeUpgradeFailed indicates that upgrade failed
7274
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"
7375

pkg/apis/deployment/v2alpha1/member_status_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelect
149149
return m, nil
150150
}
151151
}
152+
for _, m := range l {
153+
if m.Conditions.IsTrue(ConditionTypeScaleDownCandidate) {
154+
return m, nil
155+
}
156+
}
152157
// Try to find a not ready member
153158
for _, m := range l {
154159
if m.Phase.IsPending() {

pkg/deployment/reconcile/plan_builder_high.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (r *Reconciler) createHighPlan(ctx context.Context, apiObject k8sutil.APIOb
5858
ApplyIfEmpty(r.createTopologyMemberConditionPlan).
5959
ApplyIfEmpty(r.createRebalancerCheckPlan).
6060
ApplyIfEmpty(r.createMemberFailedRestoreHighPlan).
61+
ApplyIfEmpty(r.scaleDownCandidate).
6162
ApplyWithBackOff(BackOffCheck, time.Minute, r.emptyPlanBuilder)).
6263
ApplyIfEmptyWithBackOff(TimezoneCheck, time.Minute, r.createTimezoneUpdatePlan).
6364
Apply(r.createBackupInProgressConditionPlan). // Discover backups always

pkg/deployment/reconcile/plan_builder_scale.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package reconcile
2323
import (
2424
"context"
2525

26+
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
2627
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2728
"github.com/arangodb/kube-arangodb/pkg/deployment/actions"
2829
"github.com/arangodb/kube-arangodb/pkg/deployment/agency"
@@ -173,3 +174,45 @@ func getCleanedServer(ctx reconciler.ArangoAgencyGet) api.MemberToRemoveSelector
173174
return "", nil
174175
}
175176
}
177+
178+
func (r *Reconciler) scaleDownCandidate(ctx context.Context, apiObject k8sutil.APIObject,
179+
spec api.DeploymentSpec, status api.DeploymentStatus,
180+
context PlanBuilderContext) api.Plan {
181+
var plan api.Plan
182+
183+
for _, m := range status.Members.AsList() {
184+
cache, ok := context.ACS().ClusterCache(m.Member.ClusterID)
185+
if !ok {
186+
continue
187+
}
188+
189+
annotationExists := false
190+
191+
am, ok := cache.ArangoMember().V1().GetSimple(m.Member.ArangoMemberName(context.GetName(), m.Group))
192+
if !ok {
193+
continue
194+
}
195+
196+
if _, ok := am.Annotations[deployment.ArangoDeploymentPodScaleDownCandidateAnnotation]; ok {
197+
annotationExists = true
198+
}
199+
200+
if pod, ok := cache.Pod().V1().GetSimple(m.Member.Pod.GetName()); ok {
201+
if _, ok := pod.Annotations[deployment.ArangoDeploymentPodScaleDownCandidateAnnotation]; ok {
202+
annotationExists = true
203+
}
204+
}
205+
206+
conditionExists := m.Member.Conditions.IsTrue(api.ConditionTypeScaleDownCandidate)
207+
208+
if annotationExists != conditionExists {
209+
if annotationExists {
210+
plan = append(plan, updateMemberConditionActionV2("Marked as ScaleDownCandidate", api.ConditionTypeScaleDownCandidate, m.Group, m.Member.ID, true, "Marked as ScaleDownCandidate", "", ""))
211+
} else {
212+
plan = append(plan, removeMemberConditionActionV2("Unmarked as ScaleDownCandidate", api.ConditionTypeScaleDownCandidate, m.Group, m.Member.ID))
213+
}
214+
}
215+
}
216+
217+
return plan
218+
}

0 commit comments

Comments
 (0)