File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package k8sutils
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67
78 redisv1beta1 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta1"
89
@@ -277,6 +278,7 @@ func getRedisReplicationMasterIP(cr *redisv1beta1.RedisSentinel) string {
277278 replicationNamespace := cr .Namespace
278279
279280 var replicationInstance redisv1beta1.RedisReplication
281+ var realMasterPod string
280282
281283 // Get Request on Dynamic Client
282284 customObject , err := generateK8sDynamicClient ().Resource (schema.GroupVersionResource {
@@ -306,13 +308,22 @@ func getRedisReplicationMasterIP(cr *redisv1beta1.RedisSentinel) string {
306308 }
307309
308310 masterPods := GetRedisNodesByRole (& replicationInstance , "master" )
309- realMasterPod := checkAttachedSlave (& replicationInstance , masterPods )
311+
312+ if len (masterPods ) == 0 {
313+ realMasterPod = ""
314+ err := errors .New ("no master pods found" )
315+ logger .Error (err , "" )
316+ } else if len (masterPods ) == 1 {
317+ realMasterPod = masterPods [0 ]
318+ } else {
319+ realMasterPod = checkAttachedSlave (& replicationInstance , masterPods )
320+ }
321+
310322 realMasterInfo := RedisDetails {
311323 PodName : realMasterPod ,
312324 Namespace : replicationNamespace ,
313325 }
314326
315327 realMasterPodIP := getRedisServerIP (realMasterInfo )
316328 return realMasterPodIP
317-
318329}
You can’t perform that action at this time.
0 commit comments