From ff91154a28235610b65f5ee26112e0ce643407ee Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Wed, 17 Feb 2021 13:25:29 +0100 Subject: [PATCH 1/9] add prestop hook for redis sentinel to failover the master --- bitnami/redis/Chart.yaml | 2 +- .../redis/templates/configmap-scripts.yaml | 35 +++++++++++++++++++ .../templates/redis-node-statefulset.yaml | 7 ++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bitnami/redis/Chart.yaml b/bitnami/redis/Chart.yaml index 9b516023109a9d..b48e3b2150a95b 100644 --- a/bitnami/redis/Chart.yaml +++ b/bitnami/redis/Chart.yaml @@ -25,4 +25,4 @@ name: redis sources: - https://github.com/bitnami/bitnami-docker-redis - http://redis.io/ -version: 12.7.4 +version: 12.7.5 diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 4d8f7c6c3bdd53..1040df33776a5e 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -280,6 +280,41 @@ 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 + is_boolean_yes() { + local -r bool="${1:-}" + # comparison is performed without regard to the case of alphabetic characters + shopt -s nocasematch + if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then + true + else + false + fi + } + + REDIS_SERVICE="{{ template "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 diff --git a/bitnami/redis/templates/redis-node-statefulset.yaml b/bitnami/redis/templates/redis-node-statefulset.yaml index 57fc658243ac88..776f3808b6eb06 100644 --- a/bitnami/redis/templates/redis-node-statefulset.yaml +++ b/bitnami/redis/templates/redis-node-statefulset.yaml @@ -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 From 6a1e8e68a58b4dbce84bdda4f06db1719f667f6d Mon Sep 17 00:00:00 2001 From: Dwight Donovan Benvenuto <0x46616c6b@users.noreply.github.com> Date: Thu, 18 Feb 2021 10:56:52 +0100 Subject: [PATCH 2/9] Update bitnami/redis/templates/configmap-scripts.yaml Co-authored-by: Juan Ariza Toledano --- bitnami/redis/templates/configmap-scripts.yaml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 1040df33776a5e..c063e1b2cb8564 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -282,16 +282,9 @@ data: exec redis-server /opt/bitnami/redis-sentinel/etc/sentinel.conf --sentinel {{- if .Values.tls.enabled }} "${ARGS[@]}" {{- end }} prestop-sentinel.sh: | #!/bin/bash - is_boolean_yes() { - local -r bool="${1:-}" - # comparison is performed without regard to the case of alphabetic characters - shopt -s nocasematch - if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then - true - else - false - fi - } + #!/bin/bash + + . /opt/bitnami/scripts/libvalidations.sh REDIS_SERVICE="{{ template "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}" From 7a2b2556d5c9c6044a8a514182f335652835ca92 Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Thu, 18 Feb 2021 10:58:07 +0100 Subject: [PATCH 3/9] fix indentation --- bitnami/redis/templates/configmap-scripts.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index c063e1b2cb8564..6c1f3f85dc20cc 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -294,12 +294,12 @@ data: 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]} + 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 From bb99391b03c095937a96d909f6b6ac7c0920f6f1 Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Thu, 18 Feb 2021 11:04:31 +0100 Subject: [PATCH 4/9] remove duplicated line --- bitnami/redis/templates/configmap-scripts.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 6c1f3f85dc20cc..8c1e4344f31334 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -282,7 +282,6 @@ data: exec redis-server /opt/bitnami/redis-sentinel/etc/sentinel.conf --sentinel {{- if .Values.tls.enabled }} "${ARGS[@]}" {{- end }} prestop-sentinel.sh: | #!/bin/bash - #!/bin/bash . /opt/bitnami/scripts/libvalidations.sh From 5cf5f55ece8f26653e7e7c51cef62359826c945e Mon Sep 17 00:00:00 2001 From: Dwight Donovan Benvenuto <0x46616c6b@users.noreply.github.com> Date: Thu, 18 Feb 2021 11:28:59 +0100 Subject: [PATCH 5/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miguel Ángel Cabrera Miñagorri --- bitnami/redis/Chart.yaml | 2 +- bitnami/redis/templates/configmap-scripts.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bitnami/redis/Chart.yaml b/bitnami/redis/Chart.yaml index b48e3b2150a95b..92e47c3a9ce06c 100644 --- a/bitnami/redis/Chart.yaml +++ b/bitnami/redis/Chart.yaml @@ -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 diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 8c1e4344f31334..2e3f2dabc1e85e 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -287,9 +287,9 @@ data: REDIS_SERVICE="{{ template "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}" - if [[ -n $REDIS_PASSWORD_FILE ]]; then - password_aux=`cat ${REDIS_PASSWORD_FILE}` - export REDIS_PASSWORD=$password_aux + 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 @@ -302,9 +302,9 @@ data: 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 + 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 + redis-cli {{- if .Values.usePassword }} -a "$REDIS_PASSWORD" {{- end }} -h "$REDIS_SERVICE" -p {{ .Values.sentinel.port }} sentinel failover mymaster fi fi {{- else }} From 017114525525bb927aad3861397c50f43d697f40 Mon Sep 17 00:00:00 2001 From: Dwight Donovan Benvenuto <0x46616c6b@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:42:02 +0100 Subject: [PATCH 6/9] Update bitnami/redis/templates/configmap-scripts.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miguel Ángel Cabrera Miñagorri --- bitnami/redis/templates/configmap-scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 2e3f2dabc1e85e..5186e5702dcda9 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -285,7 +285,7 @@ data: . /opt/bitnami/scripts/libvalidations.sh - REDIS_SERVICE="{{ template "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}" + REDIS_SERVICE="{{ include "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}" if [[ -n "$REDIS_PASSWORD_FILE" ]]; then password_aux=$(cat "$REDIS_PASSWORD_FILE") From 9fdfa422a852ef506e7c4ec03b7d6ef1f706ea6a Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Mon, 22 Feb 2021 13:43:48 +0100 Subject: [PATCH 7/9] Apply suggestions from code review --- bitnami/redis/templates/configmap-scripts.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 5186e5702dcda9..8e2b5dcade40f2 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -293,18 +293,18 @@ data: 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 }}" + 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 }}" + 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 + 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 + redis-cli {{- if .Values.usePassword }} -a "${REDIS_PASSWORD}" {{- end }} -h "${REDIS_SERVICE}" -p {{ .Values.sentinel.port }} sentinel failover mymaster fi fi {{- else }} From 510fbbea507f0bf4cc7740a41f791f0cb80cd5ad Mon Sep 17 00:00:00 2001 From: Dwight Donovan Benvenuto <0x46616c6b@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:31:36 +0100 Subject: [PATCH 8/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miguel Ángel Cabrera Miñagorri --- bitnami/redis/templates/configmap-scripts.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 8e2b5dcade40f2..2ce39c5c3cb031 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -302,9 +302,9 @@ data: 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 + 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 + redis-cli {{- if .Values.usePassword }} -a "$REDIS_PASSWORD" {{- end }} -h "$REDIS_SERVICE" -p {{ .Values.sentinel.port }} sentinel failover mymaster fi fi {{- else }} From 318987bf26ec15993d59c2cc145e4ca27915c10f Mon Sep 17 00:00:00 2001 From: Dwight Donovan Benvenuto <0x46616c6b@users.noreply.github.com> Date: Wed, 24 Feb 2021 11:04:31 +0100 Subject: [PATCH 9/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miguel Ángel Cabrera Miñagorri --- bitnami/redis/templates/configmap-scripts.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitnami/redis/templates/configmap-scripts.yaml b/bitnami/redis/templates/configmap-scripts.yaml index 2ce39c5c3cb031..e757bbf9048e40 100644 --- a/bitnami/redis/templates/configmap-scripts.yaml +++ b/bitnami/redis/templates/configmap-scripts.yaml @@ -298,11 +298,11 @@ data: 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]} + 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 + 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