Skip to content

Commit

Permalink
check master attached slave
Browse files Browse the repository at this point in the history
Signed-off-by: drivebyer <[email protected]>
  • Loading branch information
drivebyer committed Jun 4, 2024
1 parent e48c96a commit 7b97ea5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
33 changes: 15 additions & 18 deletions k8sutils/redis-sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,30 +316,27 @@ func getRedisReplicationMasterIP(ctx context.Context, client kubernetes.Interfac
}

masterPods := GetRedisNodesByRole(ctx, client, logger, &replicationInstance, "master")

if len(masterPods) == 0 {
realMasterPod = ""
err := errors.New("no master pods found")
logger.Error(err, "")
} else if len(masterPods) == 1 {
realMasterPod = masterPods[0]
} else {
for _, podName := range masterPods {
redisClient := configureRedisReplicationClient(client, logger, &replicationInstance, podName)
defer redisClient.Close()

if checkAttachedSlave(ctx, redisClient, logger, podName) > 0 {
realMasterPod = podName
break
}
logger.Error(errors.New("no master pods found"), "")
return ""

Check warning on line 321 in k8sutils/redis-sentinel.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-sentinel.go#L320-L321

Added lines #L320 - L321 were not covered by tests
}
for _, podName := range masterPods {
redisClient := configureRedisReplicationClient(client, logger, &replicationInstance, podName)
defer redisClient.Close()

Check warning on line 325 in k8sutils/redis-sentinel.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-sentinel.go#L323-L325

Added lines #L323 - L325 were not covered by tests

if checkAttachedSlave(ctx, redisClient, logger, podName) > 0 {
realMasterPod = podName
break

Check warning on line 329 in k8sutils/redis-sentinel.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-sentinel.go#L327-L329

Added lines #L327 - L329 were not covered by tests
}
}
if realMasterPod == "" {
logger.Error(errors.New("no real master pod found"), "")
return ""

Check warning on line 334 in k8sutils/redis-sentinel.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-sentinel.go#L332-L334

Added lines #L332 - L334 were not covered by tests
}

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

realMasterPodIP := getRedisServerIP(client, logger, realMasterInfo)
return realMasterPodIP
return getRedisServerIP(client, logger, realMasterInfo)

Check warning on line 341 in k8sutils/redis-sentinel.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-sentinel.go#L341

Added line #L341 was not covered by tests
}
7 changes: 0 additions & 7 deletions tests/e2e-chainsaw/v1beta2/ha-failover/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ spec:
timeout: 10s
content: |
kubectl --namespace ${NAMESPACE} delete pod redis-replication-0
catch:
- description: Redis Operator Logs
podLogs:
namespace: redis-operator-system
selector: control-plane=redis-operator
container: manager
tail: -1 # tail all logs
- name: Sleep for 3 minutes
try:
Expand Down

0 comments on commit 7b97ea5

Please sign in to comment.