Skip to content

Commit

Permalink
[bitnami/redis] PreStop Hook to Initiate Failover for Sentinel on Pod…
Browse files Browse the repository at this point in the history
…Termination (bitnami#5528)

* add prestop hook for redis sentinel to failover the master

* Update bitnami/redis/templates/configmap-scripts.yaml

Co-authored-by: Juan Ariza Toledano <juanariza@vmware.com>

* fix indentation

* remove duplicated line

* Apply suggestions from code review

Co-authored-by: Miguel Ángel Cabrera Miñagorri <devgorri@gmail.com>

* Update bitnami/redis/templates/configmap-scripts.yaml

Co-authored-by: Miguel Ángel Cabrera Miñagorri <devgorri@gmail.com>

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Miguel Ángel Cabrera Miñagorri <devgorri@gmail.com>

* Apply suggestions from code review

Co-authored-by: Miguel Ángel Cabrera Miñagorri <devgorri@gmail.com>

Co-authored-by: Juan Ariza Toledano <juanariza@vmware.com>
Co-authored-by: Miguel Ángel Cabrera Miñagorri <devgorri@gmail.com>
  • Loading branch information
3 people committed Mar 30, 2021
1 parent 063567f commit d7aebfc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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.7
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 @@ -290,6 +290,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
. /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]}"
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
else
redis-cli {{- if .Values.usePassword }} -a "$REDIS_PASSWORD" {{- end }} -h "$REDIS_SERVICE" -p {{ .Values.sentinel.port }} sentinel failover 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 @@ -296,6 +296,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

0 comments on commit d7aebfc

Please sign in to comment.