Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
[stable-redis] reset sentinel list after helm upgrade
Browse files Browse the repository at this point in the history
if redis helm chart is upgraded, pods may be restartet after in-place container upgrade and get new IP addresses. Sentinels don't forget ever seen IP adresses. This job resets the sentinel lists after HELM chart updates.

Signed-off-by: btrappe <btrappe@web.de>
Signed-off-by: Bernd Trappe <btrappe@web.de>
  • Loading branch information
btrappe committed Mar 1, 2020
1 parent 911d2d6 commit baa5b79
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
11 changes: 11 additions & 0 deletions stable/redis/templates/health-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ data:
printf "\nsentinel known-sentinel {{ .Values.sentinel.masterSet }} %s %s %s", IP, PORT, $0; FOUND_RUNID=0;
}
}
parse_sentinels_reset.awk: |-
/ip/ {FOUND_IP=1}
/port/ {FOUND_PORT=1}
!/ip|port/ {
if (FOUND_IP==1) {
IP=$1; FOUND_IP=0;
}
else if (FOUND_PORT==1) {
printf "redis-cli --raw -h %s -a \"$REDIS_PASSWORD\" -p %s SENTINEL reset {{ .Values.sentinel.masterSet }}; ", IP, $1; FOUND_PORT=0;
}
}
{{- end }}
ping_readiness_master.sh: |-
{{- if .Values.usePasswordFile }}
Expand Down
63 changes: 63 additions & 0 deletions stable/redis/templates/redis-with-sentinel-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{- if .Values.sentinel.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "redis.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "redis.name" . }}
chart: {{ template "redis.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.sentinel.service.labels }}
{{ toYaml .Values.sentinel.service.labels | nindent 4 }}
{{- end }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-delete-policy": hook-succeeded , before-hook-creation
checksum/health: {{ include (print $.Template.BasePath "/health-configmap.yaml") . | sha256sum }}
spec:
backoffLimit: 1
#activeDeadlineSeconds: 120
template:
spec:
{{- include "redis.imagePullSecrets" . | indent 6 }}
restartPolicy: Never
containers:
- name: sentinel-reset
image: "{{ template "sentinel.image" . }}"
imagePullPolicy: {{ .Values.sentinel.image.pullPolicy | quote }}
{{- if .Values.securityContext.enabled }}
securityContext:
runAsUser: {{ .Values.securityContext.runAsUser }}
{{- end }}
command:
- /bin/bash
- -c
- |
$(timeout -s 9 {{ .Values.sentinel.initialCheckTimeout }} redis-cli --raw -h $REDIS_MASTER_HOST -a \"$REDIS_PASSWORD\" -p {{ .Values.sentinel.service.sentinelPort }} SENTINEL sentinels {{ .Values.sentinel.masterSet }} | awk -f /health/parse_sentinels_reset.awk)
redis-cli --raw -h $REDIS_MASTER_HOST -a \"$REDIS_PASSWORD\" -p 26379 SENTINEL reset {{ .Values.sentinel.masterSet }}
env:
- name: REDIS_MASTER_HOST
value: {{ template "redis.fullname" . }}-master-0.{{ template "redis.fullname" . }}-headless.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}
{{- if .Values.usePassword }}
{{- if .Values.usePasswordFile }}
- name: REDIS_PASSWORD_FILE
value: "/opt/bitnami/redis/secrets/redis-password"
{{- else }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "redis.secretName" . }}
key: {{ template "redis.secretPasswordKey" . }}
{{- end }}
{{- end }}
volumeMounts:
- name: health
mountPath: /health
volumes:
- name: health
configMap:
name: {{ template "redis.fullname" . }}-health
defaultMode: 0755
{{- end }}

0 comments on commit baa5b79

Please sign in to comment.