Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bitnami/redis-cluster/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 13.0.4 (2025-08-23)
## 13.1.0 (2025-09-05)

* [bitnami/redis-cluster] :zap: :arrow_up: Update dependency references ([#36172](https://github.com/bitnami/charts/pull/36172))
* [bitnami/redis-cluster]: add preStop hook that gracefully fails over master nodes on pod termination ([#36221](https://github.com/bitnami/charts/pull/36221))

## <small>13.0.4 (2025-08-23)</small>

* [bitnami/redis-cluster] :zap: :arrow_up: Update dependency references (#36172) ([2060aa9](https://github.com/bitnami/charts/commit/2060aa94b82bd7e0b030a310acf5c45f3b3dceda)), closes [#36172](https://github.com/bitnami/charts/issues/36172)

## <small>13.0.3 (2025-08-18)</small>

Expand Down
2 changes: 1 addition & 1 deletion bitnami/redis-cluster/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ maintainers:
name: redis-cluster
sources:
- https://github.com/bitnami/charts/tree/main/bitnami/redis-cluster
version: 13.0.5
version: 13.1.0
1 change: 1 addition & 0 deletions bitnami/redis-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ See [#15075](https://github.com/bitnami/charts/issues/15075)
| `cluster.init` | Enable the initialization of the Redis(R) Cluster | `true` |
| `cluster.nodes` | The number of master nodes should always be >= 3, otherwise cluster creation will fail | `6` |
| `cluster.replicas` | Number of replicas for every master in the cluster | `1` |
| `cluster.redisShutdownWaitFailover` | Whether the Redis(R) master container waits for the failover at shutdown. | `true` |
| `cluster.externalAccess.enabled` | Enable access to the Redis | `false` |
| `cluster.externalAccess.hostMode` | Set cluster preferred endpoint type as hostname | `false` |
| `cluster.externalAccess.service.disableLoadBalancerIP` | Disable use of `Service.spec.loadBalancerIP` | `false` |
Expand Down
8 changes: 8 additions & 0 deletions bitnami/redis-cluster/templates/redis-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ spec:
{{- end }}
{{- if .Values.redis.lifecycleHooks }}
lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.redis.lifecycleHooks "context" $) | nindent 12 }}
{{- else }}
lifecycle:
preStop:
exec:
command:
- /bin/bash
- -ec
- /scripts/prestop-redis-cluster.sh
{{- end }}
{{- end }}
{{- if .Values.redis.resources }}
Expand Down
61 changes: 61 additions & 0 deletions bitnami/redis-cluster/templates/scripts-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,64 @@ data:
echo "$response"
exit 1
fi
prestop-redis-cluster.sh: |-
#!/bin/bash
set -e

# redis-cli automatically consumes credentials from the REDISCLI_AUTH variable
[[ -n "$REDIS_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_PASSWORD"
[[ -f "$REDIS_PASSWORD_FILE" ]] && export REDISCLI_AUTH="$(< "${REDIS_PASSWORD_FILE}")"

run_redis_command() {
local args=("-h" "$1")
shift
{{- if .Values.tls.enabled }}
args+=("--tls" "--cert" "{{ template "redis-cluster.tlsCert" . }}" "--key" "{{ template "redis-cluster.tlsCertKey" . }}" "--cacert" "{{ template "redis-cluster.tlsCACert" . }}" "-p" $REDIS_TLS_PORT_NUMBER)
{{- else }}
args+=("-p" $REDIS_PORT_NUMBER)
{{- end }}
redis-cli "${args[@]}" "$@"
}

is_master() {
REDIS_ROLE=$(run_redis_command 127.0.0.1 ROLE | head -1)
[[ "$REDIS_ROLE" == "master" ]]
}

get_cluster_node_id() {
CLUSTER_ID=$(run_redis_command 127.0.0.1 CLUSTER MYID | head -1)
echo $CLUSTER_ID
}

get_replica_ips() {
CLUSTER_NODE_ID=$(get_cluster_node_id)

# Get a list of replica IP addresses that could be promoted
# Use shuf to randomize the order
REPLICAS="$(run_redis_command 127.0.0.1 CLUSTER REPLICAS $CLUSTER_NODE_ID | grep -Ev "(disconnected|nofailover|noaddr|handshake)" | cut -d " " -f 2 | cut -d ":" -f 1 | shuf)"
echo "$REPLICAS" | sed '/^[[:space:]]*$/d'
}

if is_master; then
# Get list of replicas of the current master
mapfile -t REPLICA_IPS < <( get_replica_ips )

NUM_REPLICAS=${#REPLICA_IPS[@]}
echo "Found $NUM_REPLICAS available replicas"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should cover 0 replicas found. But maybe its better to add a warning message?
No replica found for failover; proceeding with shutdown


# Iterate over replicas, attempting to promote one
for REPLICA_IP in "${REPLICA_IPS[@]}"; do
echo "Going to fail over to replica at $REPLICA_IP"
result=$(run_redis_command $REPLICA_IP CLUSTER FAILOVER)

if [[ "$result" == "OK" ]]; then
{{- if .Values.cluster.redisShutdownWaitFailover }}
# Wait for clients to update their topology
sleep 10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this configurable instead of fixed 10 seconds?

Copy link
Author

@sobotklp sobotklp Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be configurable up to a maximum of {{- $.Values.redis.terminationGracePeriodSeconds }} I would think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to wait $.Values.redis.terminationGracePeriodSeconds - 10 seconds

{{- end }}
break
fi
done
else
exit 0
fi
4 changes: 4 additions & 0 deletions bitnami/redis-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,10 @@ cluster:
replicas: 1
## Configuration to access the Redis(R) Cluster from outside the Kubernetes cluster
##
## @param cluster.redisShutdownWaitFailover Whether the Redis(R) master container waits for the failover at shutdown.
##
redisShutdownWaitFailover: true

externalAccess:
## @param cluster.externalAccess.enabled Enable access to the Redis
##
Expand Down
Loading