1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] ScaleDown candidate (#1120)

This commit is contained in:
Adam Janikowski 2022-09-22 11:08:48 +02:00 committed by GitHub
parent 987cefeab5
commit 03a5659b7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 6 deletions

View file

@ -8,6 +8,7 @@
- (Debug Package) Initial commit
- (Feature) Detach PVC from deployment in Ordered indexing method
- (Feature) OPS Alerts
- (Feature) ScaleDown Candidate
## [1.2.16](https://github.com/arangodb/kube-arangodb/tree/1.2.16) (2022-09-14)
- (Feature) Add ArangoDeployment ServerGroupStatus

View file

@ -21,10 +21,11 @@
package deployment
const (
ArangoDeploymentAnnotationPrefix = "deployment.arangodb.com"
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
ArangoDeploymentPodDeleteNow = ArangoDeploymentAnnotationPrefix + "/delete_now"
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
ArangoDeploymentAnnotationPrefix = "deployment.arangodb.com"
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
ArangoDeploymentPodDeleteNow = ArangoDeploymentAnnotationPrefix + "/delete_now"
ArangoDeploymentPodScaleDownCandidateAnnotation = ArangoDeploymentAnnotationPrefix + "/scale_down_candidate"
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
)

View file

@ -68,6 +68,8 @@ const (
ConditionTypeSpecAccepted ConditionType = "SpecAccepted"
// ConditionTypeMarkedToRemove indicates that the member is marked to be removed.
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"
// ConditionTypeScaleDownCandidate indicates that the member will be picked in ScaleDown operaion.
ConditionTypeScaleDownCandidate ConditionType = "ScaleDownCandidate"
// ConditionTypeUpgradeFailed indicates that upgrade failed
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"

View file

@ -149,6 +149,11 @@ func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelect
return m, nil
}
}
for _, m := range l {
if m.Conditions.IsTrue(ConditionTypeScaleDownCandidate) {
return m, nil
}
}
// Try to find a not ready member
for _, m := range l {
if m.Phase.IsPending() {

View file

@ -68,6 +68,8 @@ const (
ConditionTypeSpecAccepted ConditionType = "SpecAccepted"
// ConditionTypeMarkedToRemove indicates that the member is marked to be removed.
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"
// ConditionTypeScaleDownCandidate indicates that the member will be picked in ScaleDown operaion.
ConditionTypeScaleDownCandidate ConditionType = "ScaleDownCandidate"
// ConditionTypeUpgradeFailed indicates that upgrade failed
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"

View file

@ -149,6 +149,11 @@ func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelect
return m, nil
}
}
for _, m := range l {
if m.Conditions.IsTrue(ConditionTypeScaleDownCandidate) {
return m, nil
}
}
// Try to find a not ready member
for _, m := range l {
if m.Phase.IsPending() {

View file

@ -58,6 +58,7 @@ func (r *Reconciler) createHighPlan(ctx context.Context, apiObject k8sutil.APIOb
ApplyIfEmpty(r.createTopologyMemberConditionPlan).
ApplyIfEmpty(r.createRebalancerCheckPlan).
ApplyIfEmpty(r.createMemberFailedRestoreHighPlan).
ApplyIfEmpty(r.scaleDownCandidate).
ApplyWithBackOff(BackOffCheck, time.Minute, r.emptyPlanBuilder)).
ApplyIfEmptyWithBackOff(TimezoneCheck, time.Minute, r.createTimezoneUpdatePlan).
Apply(r.createBackupInProgressConditionPlan). // Discover backups always

View file

@ -23,6 +23,7 @@ package reconcile
import (
"context"
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/actions"
"github.com/arangodb/kube-arangodb/pkg/deployment/agency"
@ -173,3 +174,45 @@ func getCleanedServer(ctx reconciler.ArangoAgencyGet) api.MemberToRemoveSelector
return "", nil
}
}
func (r *Reconciler) scaleDownCandidate(ctx context.Context, apiObject k8sutil.APIObject,
spec api.DeploymentSpec, status api.DeploymentStatus,
context PlanBuilderContext) api.Plan {
var plan api.Plan
for _, m := range status.Members.AsList() {
cache, ok := context.ACS().ClusterCache(m.Member.ClusterID)
if !ok {
continue
}
annotationExists := false
am, ok := cache.ArangoMember().V1().GetSimple(m.Member.ArangoMemberName(context.GetName(), m.Group))
if !ok {
continue
}
if _, ok := am.Annotations[deployment.ArangoDeploymentPodScaleDownCandidateAnnotation]; ok {
annotationExists = true
}
if pod, ok := cache.Pod().V1().GetSimple(m.Member.Pod.GetName()); ok {
if _, ok := pod.Annotations[deployment.ArangoDeploymentPodScaleDownCandidateAnnotation]; ok {
annotationExists = true
}
}
conditionExists := m.Member.Conditions.IsTrue(api.ConditionTypeScaleDownCandidate)
if annotationExists != conditionExists {
if annotationExists {
plan = append(plan, updateMemberConditionActionV2("Marked as ScaleDownCandidate", api.ConditionTypeScaleDownCandidate, m.Group, m.Member.ID, true, "Marked as ScaleDownCandidate", "", ""))
} else {
plan = append(plan, removeMemberConditionActionV2("Unmarked as ScaleDownCandidate", api.ConditionTypeScaleDownCandidate, m.Group, m.Member.ID))
}
}
}
return plan
}