Skip to content

Commit

Permalink
fix the loop call of checkAttachedSlave (#523)
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <[email protected]>
  • Loading branch information
shubham-cmyk authored Jun 15, 2023
1 parent 21d4f85 commit 0522700
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions k8sutils/redis-sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package k8sutils
import (
"context"
"encoding/json"
"errors"

redisv1beta1 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta1"

Expand Down Expand Up @@ -277,6 +278,7 @@ func getRedisReplicationMasterIP(cr *redisv1beta1.RedisSentinel) string {
replicationNamespace := cr.Namespace

var replicationInstance redisv1beta1.RedisReplication
var realMasterPod string

// Get Request on Dynamic Client
customObject, err := generateK8sDynamicClient().Resource(schema.GroupVersionResource{
Expand Down Expand Up @@ -306,13 +308,22 @@ func getRedisReplicationMasterIP(cr *redisv1beta1.RedisSentinel) string {
}

masterPods := GetRedisNodesByRole(&replicationInstance, "master")
realMasterPod := checkAttachedSlave(&replicationInstance, masterPods)

if len(masterPods) == 0 {
realMasterPod = ""
err := errors.New("no master pods found")
logger.Error(err, "")
} else if len(masterPods) == 1 {
realMasterPod = masterPods[0]
} else {
realMasterPod = checkAttachedSlave(&replicationInstance, masterPods)
}

realMasterInfo := RedisDetails{
PodName: realMasterPod,
Namespace: replicationNamespace,
}

realMasterPodIP := getRedisServerIP(realMasterInfo)
return realMasterPodIP

}

0 comments on commit 0522700

Please sign in to comment.