Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure-pipelines/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ extends:
GithubImageName: ot-container-kit/redis-operator/redis-operator
BuildDocs: false
AppVersion: "v0.15.0"
GolangVersion: "1.17"
GolangVersion: "1.17"
44 changes: 43 additions & 1 deletion controllers/rediscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{RequeueAfter: time.Second * 60}, err
}

// last Leader in redis cluster
lastLeaderPod := instance.Name + "-leader-" + strconv.Itoa(int(k8sutils.CheckRedisNodeCount(instance, "leader"))-1)
// Check if the cluster is downscaled
if leaderReplicas < k8sutils.CheckRedisNodeCount(instance, "leader") {

// 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

if !(k8sutils.VerifyLeaderPod(instance, lastLeaderPod)) {
// lastLeaderPod is slaving right now Make it the master Pod
// We have to bring a manual failover here to make it a leaderPod
// clusterFailover should also include the clusterReplicate since we have to map the followers to new leader
k8sutils.ClusterFailover(instance, lastLeaderPod)
}

// Step 1 Rehard the Cluster
k8sutils.ReshardRedisCluster(instance)
// Step 2 Remove the Follower Node
k8sutils.RemoveRedisFollowerNodesFromCluster(instance)
// Step 3 Remove the Leader Node
k8sutils.RemoveRedisNodeFromCluster(instance)
// Step 4 Rebalance the cluster
k8sutils.RebalanceRedisCluster(instance)
return ctrl.Result{RequeueAfter: time.Second * 100}, nil
}

err = k8sutils.CreateRedisLeader(instance)
if err != nil {
return ctrl.Result{RequeueAfter: time.Second * 60}, err
Expand Down Expand Up @@ -127,7 +154,17 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
leaderCount := k8sutils.CheckRedisNodeCount(instance, "leader")
if leaderCount != leaderReplicas {
reqLogger.Info("Not all leader are part of the cluster...", "Leaders.Count", leaderCount, "Instance.Size", leaderReplicas)
k8sutils.ExecuteRedisClusterCommand(instance)
if leaderCount <= 2 {
k8sutils.ExecuteRedisClusterCommand(instance)
} else {
if leaderCount < leaderReplicas {
// Scale up the cluster
// Step 2 : Add Redis Node
k8sutils.AddRedisNodeToCluster(instance)
// Step 3 Rebalance the cluster using the empty masters
k8sutils.RebalanceRedisClusterEmptyMasters(instance)
}
}
} else {
if followerReplicas > 0 {
reqLogger.Info("All leader are part of the cluster, adding follower/replicas", "Leaders.Count", leaderCount, "Instance.Size", leaderReplicas, "Follower.Replicas", followerReplicas)
Expand All @@ -147,6 +184,11 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
return ctrl.Result{RequeueAfter: time.Second * 120}, nil
}

// Check If there is No Empty Master Node
if k8sutils.CheckRedisNodeCount(instance, "") == totalReplicas {
k8sutils.CheckIfEmptyMasters(instance)
}
reqLogger.Info("Will reconcile redis cluster operator in again 10 seconds")
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
}
Expand Down
Loading