From 6c16fbdc25eaa548cf81a5f3305f59bebc139399 Mon Sep 17 00:00:00 2001 From: Mathieu REHO Date: Sat, 4 Jul 2026 19:49:24 +0200 Subject: [PATCH 1/2] fix(valkey): seed on the current master, not a reachable replica --- charts/valkey/templates/configmap.yaml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/charts/valkey/templates/configmap.yaml b/charts/valkey/templates/configmap.yaml index 0e2d5c24..989eaa12 100644 --- a/charts/valkey/templates/configmap.yaml +++ b/charts/valkey/templates/configmap.yaml @@ -335,22 +335,25 @@ data: # cold-start hint: if a failover already happened and this pod lost its # emptyDir, monitoring node-0 again would advertise a stale master until # hello-channel gossip converges. Probe the data plane for the real master. - master="$SEED_MASTER" + # Discover the node currently reporting role:master, not merely a reachable + # seed. After a failover the seed (node-0) is a live *replica*, and a + # Sentinel seeded on a replica never redirects to the real master — it would + # advertise that replica to clients. Fall back to the seed only if no node + # answers as master within the bounded budget. + master="" i=0 - until vcli -h "$master" -p "$VALKEY_PORT" ping >/dev/null 2>&1; do - i=$((i + 1)) + while :; do if m="$(find_current_master)"; then - if [ "$m" != "$master" ]; then - echo "seed $master unavailable; using discovered master $m" - master="$m" - continue - fi + master="$m" + break fi + i=$((i + 1)) if [ "$i" -ge 6 ]; then - echo "no reachable master after bounded wait; monitoring seed $master anyway" + master="$SEED_MASTER" + echo "no master discovered after bounded wait; monitoring seed $master anyway" break fi - echo "waiting for master $master:$VALKEY_PORT ($i/6)" + echo "waiting to discover current master ($i/6)" sleep 3 done cp "$BASE" "$CONF" From 3f521ac4c3b99b8538d9c3b2d9d262f31f51ccce Mon Sep 17 00:00:00 2001 From: Mathieu REHO Date: Sat, 4 Jul 2026 19:49:40 +0200 Subject: [PATCH 2/2] test(valkey): seed on the current master, not a reachable replica --- charts/valkey/tests/cluster_domain_test.yaml | 3 +++ charts/valkey/tests/ha_extension_test.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/charts/valkey/tests/cluster_domain_test.yaml b/charts/valkey/tests/cluster_domain_test.yaml index 3ca5155a..22b75ecc 100644 --- a/charts/valkey/tests/cluster_domain_test.yaml +++ b/charts/valkey/tests/cluster_domain_test.yaml @@ -63,6 +63,9 @@ tests: path: data["sentinel-entrypoint.sh"] pattern: 'SEED_MASTER="test-valkey-node-0\.test-valkey-headless\.valkey-ns\.svc\.corp\.internal"' - matchRegex: + path: data["sentinel-entrypoint.sh"] + pattern: 'if m="\$\(find_current_master\)"; then[\s\S]*?master="\$m"' + - notMatchRegex: path: data["sentinel-entrypoint.sh"] pattern: 'until vcli -h "\$master" -p "\$VALKEY_PORT" ping' diff --git a/charts/valkey/tests/ha_extension_test.yaml b/charts/valkey/tests/ha_extension_test.yaml index 35cc371c..f531d127 100644 --- a/charts/valkey/tests/ha_extension_test.yaml +++ b/charts/valkey/tests/ha_extension_test.yaml @@ -94,7 +94,7 @@ tests: template: configmap.yaml - matchRegex: path: data["sentinel-entrypoint.sh"] - pattern: 'if \[ ! -f "\$CONF" \]; then[\s\S]*?until vcli' + pattern: 'if \[ ! -f "\$CONF" \]; then[\s\S]*?find_current_master' template: configmap.yaml - matchRegex: path: data["sentinel-entrypoint.sh"]