[bitnami/redis] Add support to redis master service with useHostnames false (#35536)

This commit is contained in:
Fran Méndez
2025-12-11 10:58:16 +01:00
committed by GitHub
parent 049a7c92c7
commit de739bd746
3 changed files with 76 additions and 21 deletions

View File

@@ -1,8 +1,12 @@
# Changelog # Changelog
## 23.0.4 (2025-10-23) ## 23.0.5 (2025-12-09)
* [bitnami/redis] Fix automatic sentinel failover not triggering on graceful shutdown ([#36362](https://github.com/bitnami/charts/pull/36362)) * [bitnami/redis] Add support to redis master service with useHostnames false ([#35536](https://github.com/bitnami/charts/pull/35536))
## <small>23.0.4 (2025-10-24)</small>
* [bitnami/redis] Fix automatic sentinel failover not triggering on graceful shutdown (#36362) ([75c2a2c](https://github.com/bitnami/charts/commit/75c2a2cdf9c17094b46ad3a968ea700a241673b6)), closes [#36362](https://github.com/bitnami/charts/issues/36362)
## <small>23.0.3 (2025-10-20)</small> ## <small>23.0.3 (2025-10-20)</small>

View File

@@ -38,4 +38,4 @@ maintainers:
name: redis name: redis
sources: sources:
- https://github.com/bitnami/charts/tree/main/bitnami/redis - https://github.com/bitnami/charts/tree/main/bitnami/redis
version: 23.0.4 version: 23.0.5

View File

@@ -419,7 +419,11 @@ data:
{{- if or .Values.sentinel.masterService.enabled .Values.sentinel.service.createMaster }} {{- if or .Values.sentinel.masterService.enabled .Values.sentinel.service.createMaster }}
if [[ "${REDIS_REPLICATION_MODE}" == "master" ]]; then if [[ "${REDIS_REPLICATION_MODE}" == "master" ]]; then
# Add isMaster label to master node for master service # Add isMaster label to master node for master service
{{- if .Values.useHostnames }}
echo "${REDIS_MASTER_HOST/.*}" > /etc/shared/current echo "${REDIS_MASTER_HOST/.*}" > /etc/shared/current
{{- else }}
echo "${REDIS_MASTER_HOST}" > /etc/shared/current
{{- end }}
fi fi
{{- end }} {{- end }}
@@ -819,8 +823,13 @@ data:
#!/bin/bash #!/bin/bash
# https://download.redis.io/redis-stable/sentinel.conf # https://download.redis.io/redis-stable/sentinel.conf
{{- if .Values.useHostnames }}
echo "${6/.*}" > /etc/shared/current echo "${6/.*}" > /etc/shared/current
echo "${4/.*}" > /etc/shared/previous echo "${4/.*}" > /etc/shared/previous
{{- else }}
echo "$6" > /etc/shared/current
echo "$4" > /etc/shared/previous
{{- end }}
{{- end }} {{- end }}
{{- else }} {{- else }}
start-master.sh: | start-master.sh: |
@@ -1008,25 +1017,67 @@ metadata:
data: data:
update-master-label.sh: | update-master-label.sh: |
#!/bin/bash #!/bin/bash
while true; do set -euo pipefail
while [ ! -f "/etc/shared/current" ] && [ ! -f "/etc/shared/terminate" ]; do
sleep 1
done
if [ -f "/etc/shared/current" ]; then LOCK_FILE="/etc/shared/update-master-label.lock"
echo "new master elected, updating label(s)..."
kubectl label pod --field-selector metadata.name="$(< "/etc/shared/current")" isMaster="true" --overwrite main_logic() {
kubectl label pod --field-selector metadata.name="$(< "/etc/shared/current")" app.kubernetes.io/role- while true; do
if [ -f /etc/shared/previous ]; then while [ ! -f "/etc/shared/current" ] && [ ! -f "/etc/shared/terminate" ]; do
kubectl label pod --field-selector metadata.name="$(< "/etc/shared/previous")" isMaster="false" --overwrite sleep 1
done
if [ -f "/etc/shared/current" ]; then
current_master=$(< /etc/shared/current)
previous_master=""
[ -f /etc/shared/previous ] && previous_master=$(< /etc/shared/previous)
echo "Current master: $current_master"
if [ "$current_master" = "$previous_master" ]; then
echo "Master has not changed, skipping label update and cleaning state"
rm -f /etc/shared/current /etc/shared/previous
continue
fi
{{- if .Values.useHostnames }}
selector_key="metadata.name"
{{- else }}
selector_key="status.podIP"
{{- end }}
if [ -n "$current_master" ]; then
echo "Labeling new master $current_master"
kubectl label pod --field-selector="$selector_key=$current_master" isMaster="true" --overwrite || echo "Failed to label master"
kubectl label pod --field-selector="$selector_key=$current_master" app.kubernetes.io/role- || echo "Failed to remove role label"
fi
if [ -n "$previous_master" ]; then
echo "Previous master: $previous_master"
echo "Removing master label from previous master $previous_master"
kubectl label pod --field-selector="$selector_key=$previous_master" isMaster="false" --overwrite || echo "Failed to remove label"
fi
echo "Cleaning state files"
rm -f /etc/shared/current /etc/shared/previous
fi fi
rm "/etc/shared/current" "/etc/shared/previous"
fi
if [ -f "/etc/shared/terminate" ]; then if [ -f "/etc/shared/terminate" ]; then
echo "received signal to terminate" echo "Terminating on request"
rm "/etc/shared/terminate" rm "/etc/shared/terminate"
exit exit
fi fi
done done
}
export -f main_logic
if command -v flock &> /dev/null; then
echo "flock found. Using lock file $LOCK_FILE to prevent race conditions."
flock -n "$LOCK_FILE" bash -c "main_logic"
else
echo "WARNING: flock command not found in the system. Running without lock."
echo "This could cause race conditions in a multi-replica setup."
main_logic
fi
{{- end }} {{- end }}