From cbecfb36eae648733d25fb4dbf23981e5fed4025 Mon Sep 17 00:00:00 2001 From: Luca Miccini Date: Thu, 8 Jan 2026 15:59:28 +0100 Subject: [PATCH] Fix flaky Redis failover test The previous test used 'grep address | grep -v redis-redis-0' which had several issues: 1. The grep pattern was too generic and would fail if no 'address' field existed in the sentinel info output 2. Filtering with grep -v would produce no output (and fail) if the only address was redis-redis-0, which could happen during the failover window 3. The test didn't explicitly verify which pod became the new master This fix: - Uses the more reliable 'SENTINEL master mymaster' command to get structured master information - Explicitly compares the master IP with redis-redis-0's IP - Provides clear success/failure messages for debugging - Makes the test more robust against timing issues during failover This addresses the flaky CI failures seen in kuttl Redis HA tests. --- test/kuttl/tests/redis/05-assert.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/kuttl/tests/redis/05-assert.yaml b/test/kuttl/tests/redis/05-assert.yaml index f1d584e7..989f3310 100644 --- a/test/kuttl/tests/redis/05-assert.yaml +++ b/test/kuttl/tests/redis/05-assert.yaml @@ -14,4 +14,15 @@ commands: # there should be only a single pod accessible from the redis service oc -n $NAMESPACE get endpoints redis -o json | jq '.subsets[0].addresses | length' # the first pod should no longer be the master after the failover - echo "$SENTINELDATA" | grep address | grep -v redis-redis-0 + # Check that the master address does NOT contain redis-redis-0 + # Using sentinel's MASTER command for more reliable check + MASTER_INFO=$(oc rsh -n $NAMESPACE -c sentinel redis-redis-0 redis-cli -p 26379 SENTINEL master mymaster) + MASTER_IP=$(echo "$MASTER_INFO" | grep -A1 "^ip$" | tail -n1) + # Get the IP of redis-redis-0 to compare + POD_0_IP=$(oc get pod redis-redis-0 -n $NAMESPACE -o jsonpath='{.status.podIP}') + # Failover successful if master IP is different from redis-redis-0 IP + if [ "$MASTER_IP" = "$POD_0_IP" ]; then + echo "FAIL: redis-redis-0 ($POD_0_IP) is still the master, failover did not complete" + exit 1 + fi + echo "SUCCESS: Master is now at $MASTER_IP (redis-redis-0 is at $POD_0_IP)"