Skip to content

Commit 891b855

Browse files
authored
fix: Fix the issue where Sentinel fails to monitor one replica replication (#1481)
* fix: Solve the issue where Sentinel fails to work when starting 1 Master Replication Signed-off-by: tcxdgit <[email protected]> * fix: Fix failure to get monitorAddr in reconcileSentinel for single instance Signed-off-by: tcxdgit <[email protected]> --------- Signed-off-by: tcxdgit <[email protected]>
1 parent 3d52fdb commit 891b855

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

internal/controller/common/redis/check.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ func (c *checker) GetMasterFromReplication(ctx context.Context, rr *rr.RedisRepl
9191
if count != 0 {
9292
realMasterPod = pod
9393
break
94+
} else {
95+
replicaNum := *sts.Spec.Replicas
96+
if replicaNum == 1 {
97+
realMasterPod = pod
98+
break
99+
}
94100
}
95101
}
96102
return realMasterPod, nil

internal/k8sutils/redis-sentinel.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,23 @@ func getRedisReplicationMasterPod(ctx context.Context, client kubernetes.Interfa
340340
log.FromContext(ctx).Error(errors.New("no master pods found"), "")
341341
return emptyRedisInfo
342342
}
343-
for _, podName := range masterPods {
344-
redisClient := configureRedisReplicationClient(ctx, client, &replicationInstance, podName)
345-
defer redisClient.Close()
346343

347-
if checkAttachedSlave(ctx, redisClient, podName) > 0 {
348-
realMasterPod = podName
349-
break
344+
replicasNum := *cr.Spec.Size
345+
346+
if replicasNum == 1 {
347+
realMasterPod = masterPods[0]
348+
} else {
349+
for _, podName := range masterPods {
350+
redisClient := configureRedisReplicationClient(ctx, client, &replicationInstance, podName)
351+
defer redisClient.Close()
352+
353+
if checkAttachedSlave(ctx, redisClient, podName) > 0 {
354+
realMasterPod = podName
355+
break
356+
}
350357
}
351358
}
359+
352360
if realMasterPod == "" {
353361
log.FromContext(ctx).Error(errors.New("no real master pod found"), "")
354362
return emptyRedisInfo

0 commit comments

Comments
 (0)