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] Fix issues in initialization/restarts #5603

Merged
merged 10 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
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.6
version: 12.7.7
1 change: 1 addition & 0 deletions bitnami/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ The following table lists the configurable parameters of the Redis<sup>TM</sup>
| `sentinel.failoverTimeout` | Timeout for performing a election failover | `18000` |
| `sentinel.parallelSyncs` | Number of parallel syncs in the cluster | `1` |
| `sentinel.port` | Redis<sup>TM</sup> Sentinel port | `26379` |
| `sentinel.cleanWait` | Seconds to wait when cleaning nodes IPs | `5` |
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
| `sentinel.configmap` | Additional Redis<sup>TM</sup> configuration for the sentinel nodes (this value is evaluated as a template) | `nil` |
| `sentinel.staticID` | Enable static IDs for sentinel replicas (If disabled IDs will be randomly generated on startup) | `false` |
| `sentinel.service.type` | Kubernetes Service type (redis sentinel) | `ClusterIP` |
Expand Down
68 changes: 67 additions & 1 deletion bitnami/redis/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ data:
{{- if and .Values.cluster.enabled .Values.sentinel.enabled }}
start-node.sh: |
#!/bin/bash
set -x
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved

is_boolean_yes() {
local -r bool="${1:-}"
# comparison is performed without regard to the case of alphabetic characters
Expand All @@ -22,10 +24,35 @@ data:
false
fi
}
retry_while() {
local cmd="${1:?cmd is missing}"
local retries="${2:-12}"
local sleep_time="${3:-5}"
local return_value=1
read -r -a command <<< "$cmd"
for ((i = 1 ; i <= retries ; i+=1 )); do
"${command[@]}" && return_value=0 && break
sleep "$sleep_time"
done
return $return_value
}
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
not_exists_dns_entry() {
myip=$(hostname -i)

if [[ -z "$(getent ahosts "$HEADLESS_SERVICE" | grep "^${myip}" )" ]]; then
echo "$HEADLESS_SERVICE does not contain the IP of this pod: ${myip}"
return 1
fi
echo "$HEADLESS_SERVICE has my IP: ${myip}"
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
return 0
}
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved

HEADLESS_SERVICE="{{ template "redis.fullname" . }}-headless.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}"
REDIS_SERVICE="{{ template "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}"

# Waits for DNS to add this ip to the service DNS entry
retry_while not_exists_dns_entry

export REDIS_REPLICATION_MODE="slave"
if [[ -z "$(getent ahosts "$HEADLESS_SERVICE" | grep -v "^$(hostname -i) ")" ]]; then
export REDIS_REPLICATION_MODE="master"
Expand Down Expand Up @@ -137,6 +164,7 @@ data:

start-sentinel.sh: |
#!/bin/bash
set -x
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
replace_in_file() {
local filename="${1:?filename is required}"
local match_regex="${2:?match regex is required}"
Expand Down Expand Up @@ -184,6 +212,28 @@ data:
host_id() {
echo "$1" | openssl sha1 | awk '{print $2}'
}
retry_while() {
local cmd="${1:?cmd is missing}"
local retries="${2:-12}"
local sleep_time="${3:-5}"
local return_value=1
read -r -a command <<< "$cmd"
for ((i = 1 ; i <= retries ; i+=1 )); do
"${command[@]}" && return_value=0 && break
sleep "$sleep_time"
done
return $return_value
}
not_exists_dns_entry() {
myip=$(hostname -i)

if [[ -z "$(getent ahosts "$HEADLESS_SERVICE" | grep "^${myip}" )" ]]; then
echo "$HEADLESS_SERVICE does not contain the IP of this pod: ${myip}"
return 1
fi
echo "$HEADLESS_SERVICE has my IP: ${myip}"
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
return 0
}

HEADLESS_SERVICE="{{ template "redis.fullname" . }}-headless.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}"
REDIS_SERVICE="{{ template "redis.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}"
Expand All @@ -207,10 +257,26 @@ data:
fi

export REDIS_REPLICATION_MODE="slave"
if [[ -z "$(getent ahosts "$HEADLESS_SERVICE" | grep -v "^$(hostname -i) ")" ]]; then

# Waits for DNS to add this ip to the service DNS entry
retry_while not_exists_dns_entry

if [[ -z "$(getent ahosts "$HEADLESS_SERVICE" | grep -v "^$(hostname -i)")" ]]; then
export REDIS_REPLICATION_MODE="master"
fi

# Clean sentineles from the current sentinel nodes
for node in $( getent ahosts "$HEADLESS_SERVICE" | grep -v "^$(hostname -i)" | cut -f 1 -d ' ' | uniq ); do
echo "Cleaning sentinels in sentinel node: $node"
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
if is_boolean_yes "$REDIS_SENTINEL_TLS_ENABLED"; then
redis-cli {{- if .Values.usePassword }} -a $REDIS_PASSWORD {{- end }} -h $node -p {{ .Values.sentinel.port }} --tls --cert ${REDIS_SENTINEL_TLS_CERT_FILE} --key ${REDIS_SENTINEL_TLS_KEY_FILE} --cacert ${REDIS_SENTINEL_TLS_CA_FILE} sentinel reset "*"
else
redis-cli {{- if .Values.usePassword }} -a $REDIS_PASSWORD {{- end }} -h $node -p {{ .Values.sentinel.port }} sentinel reset "*"
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved
fi
sleep {{ .Values.sentinel.cleanWait }}
done
echo "Sentinels clean up done"
rafariossaa marked this conversation as resolved.
Show resolved Hide resolved

if [[ "$REDIS_REPLICATION_MODE" == "master" ]]; then
REDIS_MASTER_HOST="$(hostname -i)"
REDIS_MASTER_PORT_NUMBER="{{ .Values.redisPort }}"
Expand Down
9 changes: 8 additions & 1 deletion bitnami/redis/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ sentinel:
masterSet: mymaster
initialCheckTimeout: 5
quorum: 2
downAfterMilliseconds: 60000
downAfterMilliseconds: 20000
failoverTimeout: 18000
parallelSyncs: 1
port: 26379

## Seconds to wait when cleaning nodes IPs
## When starting it will clean the sentiles IP (RESET "*") in all the nodes
## This is the time to wait before sending the command to the next node
##
cleanWait: 5

## Additional Redis(TM) configuration for the sentinel nodes
## ref: https://redis.io/topics/config
##
Expand Down