Skip to content

Commit

Permalink
feat: add sentinel to helm template (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
daddyy committed Oct 8, 2024
1 parent 741909e commit ed273a4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
63 changes: 62 additions & 1 deletion helm/oncall/templates/_env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,16 @@

{{- define "snippet.redis.host" -}}
{{ if not .Values.redis.enabled -}}
{{ required "externalRedis.host is required if not redis.enabled" .Values.externalRedis.host | quote }}
{{ required "externalRedis.host is required if not redis.enabled" .Values.externalRedis.host | quote }}
{{- else -}}
{{ include "oncall.redis.fullname" . }}-master
{{- end }}
{{- end }}

{{- define "snippet.redis.sentinel.master" -}}
{{ default "mymaster" .Values.externalRedis.sentinel.master }}
{{- end }}

{{- define "snippet.redis.port" -}}
{{ default 6379 .Values.externalRedis.port | quote }}
{{- end }}
Expand Down Expand Up @@ -540,13 +544,70 @@
{{- end }}
{{- end }}

{{- define "snippet.redis.sentinel.password.secret.name" -}}
{{ if .Values.externalRedis.sentinel.existingSecret -}}
{{ .Values.externalRedis.sentinel.existingSecret }}
{{- else -}}
{{ include "oncall.fullname" . }}-redis-sentinel-external
{{- end }}
{{- end }}

{{- define "snippet.redis.key_prefix" -}}
{{ default "" .Values.externalRedis.key_prefix | quote }}
{{- end }}

{{- define "snippet.redis.sentinel.password.secret.key" -}}
{{ if .Values.externalRedis.sentinel.existingSecret -}}
{{ required "externalRedis.sentinel.passwordKey is required if externalRedis.sentinel.existingSecret is non-empty" .Values.externalRedis.sentinel.passwordKey }}
{{- else -}}
redis-sentinel-password
{{- end }}
{{- end }}

{{- define "snippet.redis.sentinel.hosts" -}}
{{- if .Values.externalRedis.sentinel -}}
{{- $hosts := .Values.externalRedis.sentinel.hosts -}}
{{- if $hosts -}}
{{- range $index, $host := $hosts -}}
{{- if $host.host -}}
{{ if $index -}},{{- end }}{{ $host.host }}:{{ default 26379 $host.port }}
{{- else -}}
{{ required (printf "Host at index %d is required and cannot be empty." $index) $host.host }}
{{- end -}}
{{- end -}}
{{- else -}}
{{ required "At least one host must be provided." .Values.externalRedis.sentinel.hosts }}
{{- end }}
{{- end }}
{{- end }}

{{- define "snippet.redis.sentinel" -}}
- name: REDIS_SENTINELS
value: {{ include "snippet.redis.sentinel.hosts" . }}
- name: REDIS_SENTINEL_MASTER_NAME
value: {{ include "snippet.redis.sentinel.master" . }}
- name: REDIS_SENTINEL_USERNAME
value: {{ default "" .Values.externalRedis.sentinel.username | quote }}
- name: REDIS_SENTINEL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "snippet.redis.sentinel.password.secret.name" . }}
key: {{ include "snippet.redis.sentinel.password.secret.key" . | quote}}
{{- end }}

{{- define "snippet.redis.env" -}}
{{- if and (.Values.externalRedis.sentinel) (not .Values.redis.enabled) }}
{{- include "snippet.redis.sentinel" . }}
{{- else -}}
- name: REDIS_PROTOCOL
value: {{ include "snippet.redis.protocol" . }}
- name: REDIS_HOST
value: {{ include "snippet.redis.host" . }}
- name: REDIS_PORT
value: {{ include "snippet.redis.port" . }}
{{- end }}
- name: REDIS_KEY_PREFIX
value: {{ include "snippet.redis.key_prefix" . }}
- name: REDIS_DATABASE
value: {{ include "snippet.redis.database" . }}
- name: REDIS_USERNAME
Expand Down
15 changes: 15 additions & 0 deletions helm/oncall/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ data:
redis-password: {{ required "externalRedis.password is required if not redis.enabled and not externalRedis.existingSecret" .Values.externalRedis.password | b64enc | quote }}
---
{{- end }}
{{- if and (.Values.externalRedis.sentinel) (not .Values.redis.enabled) (not .Values.externalRedis.sentinel.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "oncall.fullname" . }}-redis-sentinel-external
{{- if .Values.migrate.useHook }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
{{- end }}
type: Opaque
data:
redis-sentinel-password: {{ required "externalRedis.sentinel.password is required if not redis.enabled and not externalRedis.sentinel.existingSecret" .Values.externalRedis.sentinel.password | b64enc | quote }}
---
{{- end }}
{{- if and .Values.oncall.smtp.enabled .Values.oncall.smtp.password }}
apiVersion: v1
kind: Secret
Expand Down
10 changes: 10 additions & 0 deletions helm/oncall/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,16 @@ externalRedis:
existingSecret:
# The key in the secret containing the redis password
passwordKey:
key_prefix:
sentinel:
hosts:
- host:
port:
master:
username:
password:
passwordKey:
existingSecret:

# SSL options
ssl_options:
Expand Down

0 comments on commit ed273a4

Please sign in to comment.