Skip to content

Commit 1d3543c

Browse files
authored
[redis] fix: better IPv6 compatibility (CloudPirates-io#296)
* [redis] fix: better IPv6 compatibility * [redis] bump version of the chart * [redis] bump version of the chart
1 parent ea7937f commit 1d3543c

File tree

6 files changed

+64
-27
lines changed

6 files changed

+64
-27
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.6.1
5+
version: 0.6.2
66
appVersion: "8.2.1"
77
keywords:
88
- redis

charts/redis/templates/prestop-configmap.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ data:
2727
export REDISCLI_AUTH="${REDIS_PASSWORD}"
2828
{{- end }}
2929
30+
# Set loopback address based on ipFamily configuration
31+
{{- if eq .Values.ipFamily "ipv6" }}
32+
REDIS_LOOPBACK="::1"
33+
{{- else }}
34+
REDIS_LOOPBACK="127.0.0.1"
35+
{{- end }}
36+
3037
# Function to run Redis commands
3138
run_redis_command() {
32-
local args=("-h" "127.0.0.1" "-p" "$REDIS_PORT")
39+
local args=("-h" "$REDIS_LOOPBACK" "-p" "$REDIS_PORT")
3340
redis-cli "${args[@]}" "$@"
3441
}
3542

charts/redis/templates/statefulset.yaml

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spec:
6060
else
6161
# Create minimal config if no config exists
6262
cat > /tmp/redis.conf << EOF
63-
bind 0.0.0.0
63+
bind * -::*
6464
port 6379
6565
EOF
6666
fi
@@ -209,9 +209,17 @@ spec:
209209
- /bin/sh
210210
- -c
211211
{{- if .Values.auth.enabled }}
212-
- redis-cli -a ${REDIS_PASSWORD} ping
212+
{{- if eq .Values.ipFamily "ipv6" }}
213+
- redis-cli -h "::1" -a ${REDIS_PASSWORD} ping
213214
{{- else }}
214-
- redis-cli ping
215+
- redis-cli -h "127.0.0.1" -a ${REDIS_PASSWORD} ping
216+
{{- end }}
217+
{{- else }}
218+
{{- if eq .Values.ipFamily "ipv6" }}
219+
- redis-cli -h "::1" ping
220+
{{- else }}
221+
- redis-cli -h "127.0.0.1" ping
222+
{{- end }}
215223
{{- end }}
216224
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
217225
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
@@ -225,20 +233,35 @@ spec:
225233
command:
226234
- /bin/sh
227235
- -c
228-
- |
229-
{{- if and .Values.sentinel.enabled (eq .Values.architecture "replication") }}
230-
{{- if .Values.auth.enabled }}
231-
redis-cli -a ${REDIS_PASSWORD} ping | grep -q PONG
232-
{{- else }}
233-
redis-cli ping | grep -q PONG
234-
{{- end }}
235-
{{- else }}
236-
{{- if .Values.auth.enabled }}
237-
redis-cli -a ${REDIS_PASSWORD} ping
238-
{{- else }}
239-
redis-cli ping
240-
{{- end }}
241-
{{- end }}
236+
{{- if and .Values.sentinel.enabled (eq .Values.architecture "replication") }}
237+
{{- if .Values.auth.enabled }}
238+
{{- if eq .Values.ipFamily "ipv6" }}
239+
- redis-cli -h "::1" -a ${REDIS_PASSWORD} ping | grep -q PONG
240+
{{- else }}
241+
- redis-cli -h "127.0.0.1" -a ${REDIS_PASSWORD} ping | grep -q PONG
242+
{{- end }}
243+
{{- else }}
244+
{{- if eq .Values.ipFamily "ipv6" }}
245+
- redis-cli -h "::1" ping | grep -q PONG
246+
{{- else }}
247+
- redis-cli -h "127.0.0.1" ping | grep -q PONG
248+
{{- end }}
249+
{{- end }}
250+
{{- else }}
251+
{{- if .Values.auth.enabled }}
252+
{{- if eq .Values.ipFamily "ipv6" }}
253+
- redis-cli -h "::1" -a ${REDIS_PASSWORD} ping
254+
{{- else }}
255+
- redis-cli -h "127.0.0.1" -a ${REDIS_PASSWORD} ping
256+
{{- end }}
257+
{{- else }}
258+
{{- if eq .Values.ipFamily "ipv6" }}
259+
- redis-cli -h "::1" ping
260+
{{- else }}
261+
- redis-cli -h "127.0.0.1" ping
262+
{{- end }}
263+
{{- end }}
264+
{{- end }}
242265
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
243266
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
244267
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
@@ -288,7 +311,12 @@ spec:
288311
289312
# Wait for Redis to be ready
290313
echo "Waiting for Redis to start..."
291-
while ! redis-cli {{- if .Values.auth.enabled }} -a "${REDIS_PASSWORD}"{{- end }} -h 127.0.0.1 -p {{ .Values.service.port }} ping >/dev/null 2>&1; do
314+
{{- if eq .Values.ipFamily "ipv6" }}
315+
REDIS_HOST="::1"
316+
{{- else }}
317+
REDIS_HOST="127.0.0.1"
318+
{{- end }}
319+
while ! redis-cli {{- if .Values.auth.enabled }} -a "${REDIS_PASSWORD}"{{- end }} -h "${REDIS_HOST}" -p {{ .Values.service.port }} ping >/dev/null 2>&1; do
292320
sleep 1
293321
done
294322
echo "Redis is ready"
@@ -355,7 +383,7 @@ spec:
355383
# Create Sentinel config
356384
cat > /tmp/sentinel.conf << EOF
357385
port {{ .Values.sentinel.port }}
358-
bind 0.0.0.0
386+
bind * -::*
359387
# Enable hostname resolution for Redis Sentinel
360388
sentinel resolve-hostnames yes
361389
sentinel announce-hostnames yes
@@ -407,9 +435,11 @@ spec:
407435
command:
408436
- /bin/sh
409437
- -c
410-
- |
411-
# Check if sentinel is responding
412-
redis-cli -h 127.0.0.1 -p {{ .Values.sentinel.port }} {{- if .Values.auth.enabled }} -a "${REDIS_PASSWORD}"{{- end }} ping | grep -q PONG
438+
{{- if eq .Values.ipFamily "ipv6" }}
439+
- redis-cli -h "::1" -p {{ .Values.sentinel.port }} {{- if .Values.auth.enabled }} -a "${REDIS_PASSWORD}"{{- end }} ping | grep -q PONG
440+
{{- else }}
441+
- redis-cli -h "127.0.0.1" -p {{ .Values.sentinel.port }} {{- if .Values.auth.enabled }} -a "${REDIS_PASSWORD}"{{- end }} ping | grep -q PONG
442+
{{- end }}
413443
initialDelaySeconds: 5
414444
periodSeconds: 10
415445
timeoutSeconds: 5

charts/redis/test-production-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ readinessProbe:
9797
config:
9898
content: |
9999
# Redis production configuration
100-
bind 0.0.0.0
100+
bind * -::*
101101
port 6379
102102
103103
# Memory management

charts/redis/tests/common-parameters_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set:
77
config:
88
content: |
99
# Redis configuration
10-
bind 0.0.0.0
10+
bind * -::*
1111
port 6379
1212
tests:
1313
- it: should use default values when nothing is overridden

charts/redis/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ config:
7070
## @param config.content Include your custom Redis configurations here as string
7171
content: |
7272
# Redis configuration
73-
bind 0.0.0.0
73+
bind * -::*
7474
port 6379
7575
## param config.existingConfigmap Name of an existing Configmap to use instead of creating one
7676
existingConfigmap: ""

0 commit comments

Comments
 (0)