diff --git a/api/status/redis-cluster_status.go b/api/status/redis-cluster_status.go index d80b6fca0..8657d31ef 100644 --- a/api/status/redis-cluster_status.go +++ b/api/status/redis-cluster_status.go @@ -7,6 +7,10 @@ const ( InitializingClusterLeaderReason string = "RedisCluster is initializing leaders" InitializingClusterFollowerReason string = "RedisCluster is initializing followers" BootstrapClusterReason string = "RedisCluster is bootstrapping" + ScalingDownLeaderClusterReason string = "RedisCluster is scaling down leaders" + ScalingDownFollowerClusterReason string = "RedisCluster is scaling down followers" + ReshardingClusterReason string = "RedisCluster is resharding" + RebalanceClusterReason string = "RedisCluster is rebalancing" ) // Status Field of the Redis Cluster @@ -14,5 +18,8 @@ const ( RedisClusterReady RedisClusterState = "Ready" RedisClusterInitializing RedisClusterState = "Initializing" RedisClusterBootstrap RedisClusterState = "Bootstrap" + RedisClusterScalingDown RedisClusterState = "ScalingDown" + RedisClusterResharding RedisClusterState = "Resharding" + RedisClusterRebalancing RedisClusterState = "Rebalancing" // RedisClusterFailed RedisClusterState = "Failed" ) diff --git a/controllers/rediscluster_controller.go b/controllers/rediscluster_controller.go index 458e96a79..11cef9b4b 100644 --- a/controllers/rediscluster_controller.go +++ b/controllers/rediscluster_controller.go @@ -71,7 +71,8 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request // Check if the cluster is downscaled if leaderReplicas < instance.Status.ReadyLeaderReplicas { - + leaderStatusCount := instance.Status.ReadyLeaderReplicas + followerStatusCount := instance.Status.ReadyFollowerReplicas // Imp if the last index of leader sts is not leader make it then // check whether the redis is leader or not ? // if not true then make it leader pod @@ -84,12 +85,20 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request } // Step 1 Rehard the Cluster + // Change the status of the cluster to resharding don't update the leader and follower count + k8sutils.UpdateRedisClusterStatus(instance, status.RedisClusterResharding, status.ReshardingClusterReason, leaderStatusCount, followerStatusCount) k8sutils.ReshardRedisCluster(instance) // Step 2 Remove the Follower Node + // Change the status of the cluster to scaling down follower update follower count + k8sutils.UpdateRedisClusterStatus(instance, status.RedisClusterScalingDown, status.ScalingDownFollowerClusterReason, leaderStatusCount, followerStatusCount-1) k8sutils.RemoveRedisFollowerNodesFromCluster(ctx, instance) // Step 3 Remove the Leader Node + // Change the status of the cluster to scaling down leader update leader count + k8sutils.UpdateRedisClusterStatus(instance, status.RedisClusterScalingDown, status.ScalingDownLeaderClusterReason, leaderStatusCount-1, followerStatusCount-1) k8sutils.RemoveRedisNodeFromCluster(ctx, instance) // Step 4 Rebalance the cluster + // Change the status of the cluster to rebalancing + k8sutils.UpdateRedisClusterStatus(instance, status.RedisClusterRebalancing, status.RebalanceClusterReason, leaderStatusCount-1, followerStatusCount-1) k8sutils.RebalanceRedisCluster(instance) return ctrl.Result{RequeueAfter: time.Second * 100}, nil }