Skip to content

Commit 736836c

Browse files
authored
fix: should get the really leader count when scale in (#885)
* fix: should get the really leader count when scale in Signed-off-by: drivebyer <yang.wu@daocloud.io> * fix timeout Signed-off-by: drivebyer <yang.wu@daocloud.io> * fix test Signed-off-by: drivebyer <yang.wu@daocloud.io> --------- Signed-off-by: drivebyer <yang.wu@daocloud.io>
1 parent 7999a05 commit 736836c

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

controllers/rediscluster_controller.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,10 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
7474
}
7575

7676
// Check if the cluster is downscaled
77-
if leaderReplicas < instance.Status.ReadyLeaderReplicas {
78-
reqLogger.Info("Redis cluster is downscaling...", "Ready.ReadyLeaderReplicas", instance.Status.ReadyLeaderReplicas, "Expected.ReadyLeaderReplicas", leaderReplicas)
79-
80-
// loop count times to remove the latest leader/follower pod
81-
count := instance.Status.ReadyLeaderReplicas - leaderReplicas
82-
for i := int32(0); i < count; i++ {
83-
reqLogger.Info("Redis cluster is downscaling", "The times of loop", i)
84-
77+
if leaderCount := k8sutils.CheckRedisNodeCount(ctx, r.K8sClient, r.Log, instance, "leader"); leaderReplicas < leaderCount {
78+
reqLogger.Info("Redis cluster is downscaling...", "Current.LeaderReplicas", leaderCount, "Desired.LeaderReplicas", leaderReplicas)
79+
for shardIdx := leaderCount - 1; shardIdx >= leaderReplicas; shardIdx-- {
80+
reqLogger.Info("Remove the shard", "Shard.Index", shardIdx)
8581
// Imp if the last index of leader sts is not leader make it then
8682
// check whether the redis is leader or not ?
8783
// if not true then make it leader pod
@@ -100,11 +96,7 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
10096
// Step 3 Rebalance the cluster
10197
k8sutils.RebalanceRedisCluster(r.K8sClient, r.Log, instance)
10298
reqLogger.Info("Redis cluster is downscaled... Rebalancing the cluster is done")
103-
err = k8sutils.UpdateRedisClusterStatus(instance, status.RedisClusterReady, status.ReadyClusterReason, leaderReplicas, leaderReplicas, r.Dk8sClient)
104-
if err != nil {
105-
return ctrl.Result{}, err
106-
}
107-
return ctrl.Result{RequeueAfter: time.Second * 60}, nil
99+
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
108100
}
109101

110102
// Mark the cluster status as initializing if there are no leader or follower nodes

tests/_config/chainsaw-configuration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ spec:
99
timeouts:
1010
apply: 5m
1111
delete: 5m
12-
assert: 10m
13-
error: 10m
12+
assert: 20m
13+
error: 20m

tests/e2e-chainsaw/v1beta2/scaling/redis-cluster/chainsaw-test.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ spec:
3737
try:
3838
- assert:
3939
file: cluster-scale-out-status-03.yaml
40+
41+
- name: Scale In Redis Cluster
42+
try:
43+
- apply:
44+
file: cluster.yaml
45+
- assert:
46+
file: cluster-status-00.yaml

0 commit comments

Comments
 (0)