Skip to content

Commit a962c04

Browse files
committed
[redis] return fqdn for sentinel replicas lookup (#700)
* [redis] use fqdn for sentinel redis replicas, to avoid problems when calling it cross namespaces
1 parent 14f2bdc commit a962c04

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

charts/redis/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: redis
33
description: An open source, in-memory data structure store used as a database, cache, and message broker.
44
type: application
5-
version: 0.16.5
5+
version: 0.16.6
66
appVersion: "8.4.0"
77
keywords:
88
- redis

charts/redis/templates/statefulset.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ spec:
7878
7979
# Check if any sentinel is already running and knows the master
8080
for i in $(seq 0 {{ sub .Values.replicaCount 1 }}); do
81-
SENTINEL_HOST="{{ include "redis.fullname" . }}-${i}.{{ include "redis.fullname" . }}-headless"
81+
SENTINEL_HOST="{{ include "redis.fullname" . }}-${i}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
8282
MASTER_INFO=$(redis-cli -h "${SENTINEL_HOST}" -p {{ .Values.sentinel.port }} {{- if .Values.auth.sentinel }} -a "${REDIS_PASSWORD}"{{- end }} sentinel get-master-addr-by-name {{ .Values.sentinel.masterName }} 2>/dev/null | head -1 || echo "")
8383
if [ -n "$MASTER_INFO" ] && [ "$MASTER_INFO" != "Could not connect" ]; then
8484
CURRENT_MASTER="$MASTER_INFO"
@@ -92,7 +92,7 @@ spec:
9292
if [ "$SENTINEL_FOUND" = true ] && [ -n "$CURRENT_MASTER" ]; then
9393
# Sentinel knows the master - configure accordingly
9494
MY_HOSTNAME=$(hostname)
95-
MY_HOSTNAME_FQDN="${MY_HOSTNAME}.{{ include "redis.fullname" . }}-headless"
95+
MY_HOSTNAME_FQDN="${MY_HOSTNAME}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
9696
MY_IP=$(hostname -i)
9797
9898
# Check if I am the master by hostname or IP
@@ -110,7 +110,7 @@ spec:
110110
if [ "$POD_ORDINAL" != "0" ]; then
111111
echo "Bootstrap mode: configuring as replica of pod-0"
112112
# Use hostname-based replication for better resilience
113-
MASTER_HOSTNAME="{{ include "redis.fullname" . }}-0.{{ include "redis.fullname" . }}-headless"
113+
MASTER_HOSTNAME="{{ include "redis.fullname" . }}-0.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
114114
echo "replicaof $MASTER_HOSTNAME {{ if .Values.tls.enabled }}{{ .Values.tls.port }}{{ else }}{{ .Values.service.port }}{{ end }}" >> /tmp/redis.conf
115115
echo "Bootstrap replica using pod-0 hostname: $MASTER_HOSTNAME"
116116
{{- if .Values.auth.enabled }}
@@ -147,10 +147,10 @@ spec:
147147
echo "slave-announce-ip ${MY_IP}" >> /tmp/redis.conf
148148
echo "slave-announce-port {{ if .Values.tls.enabled }}{{ .Values.tls.port }}{{ else }}{{ .Values.service.port }}{{ end }}" >> /tmp/redis.conf
149149
{{- else }}
150-
echo "Using hostname: ${HOSTNAME}.{{ include "redis.fullname" . }}-headless"
151-
echo "replica-announce-ip ${HOSTNAME}.{{ include "redis.fullname" . }}-headless" >> /tmp/redis.conf
150+
echo "Using hostname: ${HOSTNAME}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
151+
echo "replica-announce-ip ${HOSTNAME}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}" >> /tmp/redis.conf
152152
echo "replica-announce-port {{ if .Values.tls.enabled }}{{ .Values.tls.port }}{{ else }}{{ .Values.service.port }}{{ end }}" >> /tmp/redis.conf
153-
echo "slave-announce-ip ${HOSTNAME}.{{ include "redis.fullname" . }}-headless" >> /tmp/redis.conf
153+
echo "slave-announce-ip ${HOSTNAME}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}" >> /tmp/redis.conf
154154
echo "slave-announce-port {{ if .Values.tls.enabled }}{{ .Values.tls.port }}{{ else }}{{ .Values.service.port }}{{ end }}" >> /tmp/redis.conf
155155
{{- end }}
156156
@@ -161,7 +161,7 @@ spec:
161161
# Replication without Sentinel: pod-0 is always master, others are replicas
162162
if [ "$POD_ORDINAL" != "0" ]; then
163163
echo "Configuring as replica of pod-0 (master)"
164-
MASTER_HOSTNAME="{{ include "redis.fullname" . }}-0.{{ include "redis.fullname" . }}-headless"
164+
MASTER_HOSTNAME="{{ include "redis.fullname" . }}-0.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
165165
echo "replicaof $MASTER_HOSTNAME {{ if .Values.tls.enabled }}{{ .Values.tls.port }}{{ else }}{{ .Values.service.port }}{{ end }}" >> /tmp/redis.conf
166166
{{- if .Values.auth.enabled }}
167167
echo "masterauth ${REDIS_PASSWORD}" >> /tmp/redis.conf
@@ -394,7 +394,7 @@ spec:
394394
echo "Checking existing Sentinels for current master..."
395395
for i in $(seq 0 {{ sub .Values.replicaCount 1 }}); do
396396
if [ "$i" != "$POD_ORDINAL" ]; then
397-
SENTINEL_HOST="{{ include "redis.fullname" . }}-${i}.{{ include "redis.fullname" . }}-headless"
397+
SENTINEL_HOST="{{ include "redis.fullname" . }}-${i}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
398398
EXISTING_MASTER=$(redis-cli -h "${SENTINEL_HOST}" -p {{ .Values.sentinel.port }} {{- if .Values.auth.sentinel }} -a "${REDIS_PASSWORD}"{{- end }} sentinel get-master-addr-by-name {{ .Values.sentinel.masterName }} 2>/dev/null | head -1 || echo "")
399399
if [ -n "$EXISTING_MASTER" ] && [ "$EXISTING_MASTER" != "Could not connect" ]; then
400400
MASTER_HOST="$EXISTING_MASTER"
@@ -469,7 +469,7 @@ spec:
469469
sentinel_link_buffer_size 32768
470470
# Allow sentinels to discover each other
471471
{{ if .Values.sentinel.config.announceHostnames }}
472-
sentinel announce-ip ${HOSTNAME}.{{ include "redis.fullname" . }}-headless
472+
sentinel announce-ip ${HOSTNAME}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}
473473
{{- else }}
474474
sentinel announce-ip ${SENTINEL_IP}
475475
{{- end }}
@@ -481,7 +481,7 @@ spec:
481481
# Add known sentinels to help with discovery (using hostnames for resilience)
482482
for i in $(seq 0 {{ sub .Values.replicaCount 1 }}); do
483483
if [ "$i" != "$POD_ORDINAL" ]; then
484-
SENTINEL_HOST="{{ include "redis.fullname" . }}-${i}.{{ include "redis.fullname" . }}-headless"
484+
SENTINEL_HOST="{{ include "redis.fullname" . }}-${i}.{{ include "redis.fullname" . }}-headless.{{ include "cloudpirates.namespace" . }}.svc.{{ .Values.clusterDomain }}"
485485
# Test if the host is resolvable before adding
486486
if getent hosts "$SENTINEL_HOST" >/dev/null 2>&1; then
487487
SENTINEL_IP=$(getent hosts "$SENTINEL_HOST" | awk '{print $1}' | head -1)

0 commit comments

Comments
 (0)