Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitnami/redis] PreStop Hook to Initiate Failover for Sentinel on PodTermination #5528

Merged
merged 12 commits into from
Feb 26, 2021
2 changes: 1 addition & 1 deletion bitnami/redis/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ name: redis
sources:
- https://github.com/bitnami/bitnami-docker-redis
- http://redis.io/
version: 12.7.5
version: 12.8.0
27 changes: 27 additions & 0 deletions bitnami/redis/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,33 @@ data:
{{ .Values.sentinel.preExecCmds | nindent 4 }}
{{- end }}
exec redis-server /opt/bitnami/redis-sentinel/etc/sentinel.conf --sentinel {{- if .Values.tls.enabled }} "${ARGS[@]}" {{- end }}
prestop-sentinel.sh: |
#!/bin/bash
0x46616c6b marked this conversation as resolved.
Show resolved Hide resolved

. /opt/bitnami/scripts/libvalidations.sh

REDIS_SERVICE="{{ include "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}"

if [[ -n "$REDIS_PASSWORD_FILE" ]]; then
password_aux=$(cat "$REDIS_PASSWORD_FILE")
export REDIS_PASSWORD="$password_aux"
fi

if is_boolean_yes "$REDIS_SENTINEL_TLS_ENABLED"; then
sentinel_info_command="redis-cli {{- if .Values.usePassword }} -a ${REDIS_PASSWORD} {{- end }} -h ${REDIS_SERVICE} -p {{ .Values.sentinel.port }} --tls --cert ${REDIS_SENTINEL_TLS_CERT_FILE} --key ${REDIS_SENTINEL_TLS_KEY_FILE} --cacert ${REDIS_SENTINEL_TLS_CA_FILE} sentinel get-master-addr-by-name {{ .Values.sentinel.masterSet }}"
else
sentinel_info_command="redis-cli {{- if .Values.usePassword }} -a ${REDIS_PASSWORD} {{- end }} -h ${REDIS_SERVICE} -p {{ .Values.sentinel.port }} sentinel get-master-addr-by-name {{ .Values.sentinel.masterSet }}"
fi
REDIS_SENTINEL_INFO=($($sentinel_info_command))
REDIS_MASTER_HOST=${REDIS_SENTINEL_INFO[0]}
0x46616c6b marked this conversation as resolved.
Show resolved Hide resolved

if [[ "$REDIS_MASTER_HOST" == "$(hostname -i)" ]]; then
if is_boolean_yes "$REDIS_SENTINEL_TLS_ENABLED"; then
redis-cli {{- if .Values.usePassword }} -a "$REDIS_PASSWORD" {{- end }} -h "$REDIS_SERVICE" -p {{ .Values.sentinel.port }} --tls --cert "${REDIS_SENTINEL_TLS_CERT_FILE}" --key "$REDIS_SENTINEL_TLS_KEY_FILE" --cacert "$REDIS_SENTINEL_TLS_CA_FILE" sentinel failover mymaster
0x46616c6b marked this conversation as resolved.
Show resolved Hide resolved
else
redis-cli {{- if .Values.usePassword }} -a "$REDIS_PASSWORD" {{- end }} -h "$REDIS_SERVICE" -p {{ .Values.sentinel.port }} sentinel failover mymaster
Copy link
Contributor

@srueg srueg Apr 12, 2021

Choose a reason for hiding this comment

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

Shouldn't this use the configured {{ .Values.sentinel.masterSet }} instead of hard-coding mymaster?

fi
fi
{{- else }}
start-master.sh: |
#!/bin/bash
Expand Down
7 changes: 7 additions & 0 deletions bitnami/redis/templates/redis-node-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ spec:
{{- else if .Values.sentinel.customReadinessProbe }}
readinessProbe: {{- toYaml .Values.sentinel.customReadinessProbe | nindent 12 }}
{{- end }}
lifecycle:
preStop:
exec:
command:
- /bin/bash
- -c
- /opt/bitnami/scripts/start-scripts/prestop-sentinel.sh
resources: {{- toYaml .Values.sentinel.resources | nindent 12 }}
volumeMounts:
- name: start-scripts
Expand Down