Skip to content

Commit

Permalink
Add status
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
  • Loading branch information
shubham-cmyk committed Oct 29, 2023
1 parent d073f9d commit 11f7ba0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/status/redis-cluster_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ 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
const (
RedisClusterReady RedisClusterState = "Ready"
RedisClusterInitializing RedisClusterState = "Initializing"
RedisClusterBootstrap RedisClusterState = "Bootstrap"
RedisClusterScalingDown RedisClusterState = "ScalingDown"
RedisClusterResharding RedisClusterState = "Resharding"
RedisClusterRebalancing RedisClusterState = "Rebalancing"
// RedisClusterFailed RedisClusterState = "Failed"
)
11 changes: 10 additions & 1 deletion controllers/rediscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 11f7ba0

Please sign in to comment.