@@ -119,8 +119,13 @@ func (s *StatusSyncer) Sync(ctx context.Context) (syncer.SyncResult, error) {
119119
120120 s .Status .ReadyNodes = len (readyNodes )
121121 if s .Status .ReadyNodes == int (* s .Spec .Replicas ) && int (* s .Spec .Replicas ) != 0 {
122- s .Status .State = apiv1alpha1 .ClusterReadyState
123- clusterCondition .Type = apiv1alpha1 .ConditionReady
122+ if err := s .reconcileXenon (s .Status .ReadyNodes ); err != nil {
123+ clusterCondition .Message = fmt .Sprintf ("%s" , err )
124+ clusterCondition .Type = apiv1alpha1 .ConditionError
125+ } else {
126+ s .Status .State = apiv1alpha1 .ClusterReadyState
127+ clusterCondition .Type = apiv1alpha1 .ConditionReady
128+ }
124129 }
125130
126131 if len (s .Status .Conditions ) == 0 {
@@ -163,9 +168,13 @@ func (s *StatusSyncer) updateClusterStatus() apiv1alpha1.ClusterCondition {
163168 // When the cluster is ready or closed, the number of replicas changes,
164169 // indicating that the cluster is updating nodes.
165170 if oldState == apiv1alpha1 .ClusterReadyState || oldState == apiv1alpha1 .ClusterCloseState {
166- if int (* s .Spec .Replicas ) != s .Status .ReadyNodes {
167- clusterCondition .Type = apiv1alpha1 .ConditionUpdate
168- s .Status .State = apiv1alpha1 .ClusterUpdateState
171+ if int (* s .Spec .Replicas ) > s .Status .ReadyNodes {
172+ clusterCondition .Type = apiv1alpha1 .ConditionScaleOut
173+ s .Status .State = apiv1alpha1 .ClusterScaleOutState
174+ return clusterCondition
175+ } else if int (* s .Spec .Replicas ) < s .Status .ReadyNodes {
176+ clusterCondition .Type = apiv1alpha1 .ConditionScaleIn
177+ s .Status .State = apiv1alpha1 .ClusterScaleInState
169178 return clusterCondition
170179 }
171180 }
@@ -302,6 +311,53 @@ func (s *StatusSyncer) updateNodeRaftStatus(node *apiv1alpha1.NodeStatus) error
302311 return nil
303312}
304313
314+ func (s * StatusSyncer ) reconcileXenon (readyNodes int ) error {
315+ expectXenonNodes := s .getExpectXenonNodes (readyNodes )
316+ for _ , nodeStatus := range s .Status .Nodes {
317+ toRemove := utils .StringDiffIn (nodeStatus .RaftStatus .Nodes , expectXenonNodes )
318+ if err := s .removeNodesFromXenon (nodeStatus .Name , toRemove ); err != nil {
319+ return err
320+ }
321+ toAdd := utils .StringDiffIn (expectXenonNodes , nodeStatus .RaftStatus .Nodes )
322+ if err := s .addNodesInXenon (nodeStatus .Name , toAdd ); err != nil {
323+ return err
324+ }
325+ }
326+ return nil
327+ }
328+
329+ func (s * StatusSyncer ) getExpectXenonNodes (readyNodes int ) []string {
330+ expectXenonNodes := []string {}
331+ for i := 0 ; i < readyNodes ; i ++ {
332+ expectXenonNodes = append (expectXenonNodes , fmt .Sprintf ("%s:%d" , s .GetPodHostName (i ), utils .XenonPort ))
333+ }
334+ return expectXenonNodes
335+ }
336+
337+ func (s * StatusSyncer ) removeNodesFromXenon (host string , toRemove []string ) error {
338+ if err := s .XenonExecutor .XenonPing (host ); err != nil {
339+ return err
340+ }
341+ for _ , removeHost := range toRemove {
342+ if err := s .XenonExecutor .ClusterRemove (host , removeHost ); err != nil {
343+ return err
344+ }
345+ }
346+ return nil
347+ }
348+
349+ func (s * StatusSyncer ) addNodesInXenon (host string , toAdd []string ) error {
350+ if err := s .XenonExecutor .XenonPing (host ); err != nil {
351+ return err
352+ }
353+ for _ , addHost := range toAdd {
354+ if err := s .XenonExecutor .ClusterAdd (host , addHost ); err != nil {
355+ return err
356+ }
357+ }
358+ return nil
359+ }
360+
305361// setPodHealthy set the pod lable healthy.
306362func (s * StatusSyncer ) setPodHealthy (ctx context.Context , pod * corev1.Pod , node * apiv1alpha1.NodeStatus ) error {
307363 healthy := "no"
0 commit comments