@@ -23,6 +23,7 @@ package reconcile
2323import (
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