Skip to content

Commit

Permalink
Added existingSecret support for mysql and redis, fixed layout of tem…
Browse files Browse the repository at this point in the history
…plates/_env.tpl for redis to follow the same format across whole file
  • Loading branch information
timchenko-a authored and artem-timchenko committed Dec 9, 2022
1 parent 635168a commit 91a9cb3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion helm/oncall/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.1.0
version: 1.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
4 changes: 4 additions & 0 deletions helm/oncall/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ externalMysql:
db_name:
user:
password:
existingSecret: ""
passwordKey: ""
```
### Connect external PostgreSQL
Expand Down Expand Up @@ -246,6 +248,8 @@ redis:
externalRedis:
host:
password:
existingSecret: ""
passwordKey: ""
```
## Update
Expand Down
44 changes: 32 additions & 12 deletions helm/oncall/templates/_env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,27 @@ http://{{ include "oncall.grafana.fullname" . }}
valueFrom:
secretKeyRef:
name: {{ include "snippet.mysql.password.secret.name" . }}
key: mariadb-root-password
key: {{ include "snippet.mysql.password.secret.key" . }}
{{- end }}

{{- define "snippet.mysql.password.secret.name" -}}
{{- if and (not .Values.mariadb.enabled) .Values.externalMysql.password -}}
{{ include "oncall.fullname" . }}-mysql-external
{{- else if and (not .Values.mariadb.enabled) .Values.externalMysql.existingSecret -}}
{{ .Values.externalMysql.existingSecret }}
{{- else -}}
{{ include "oncall.mariadb.fullname" . }}
{{- end -}}
{{- end -}}

{{- define "snippet.mysql.password.secret.key" -}}
{{- if and (not .Values.mariadb.enabled) .Values.externalMysql.passwordKey -}}
{{ .Values.externalMysql.passwordKey }}
{{- else -}}
"mariadb-root-password"
{{- end -}}
{{- end -}}

{{- define "snippet.mysql.host" -}}
{{- if and (not .Values.mariadb.enabled) .Values.externalMysql.host -}}
{{- required "externalMysql.host is required if not mariadb.enabled" .Values.externalMysql.host | quote }}
Expand Down Expand Up @@ -383,6 +393,18 @@ rabbitmq-password
{{- end -}}
{{- end -}}

{{- define "snippet.redis.env" -}}
- name: REDIS_HOST
value: {{ include "snippet.redis.host" . }}
- name: REDIS_PORT
value: "6379"
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "snippet.redis.password.secret.name" . }}
key: {{ include "snippet.redis.password.secret.key" . }}
{{- end }}

{{- define "snippet.redis.host" -}}
{{- if and (not .Values.redis.enabled) .Values.externalRedis.host -}}
{{- required "externalRedis.host is required if not redis.enabled" .Values.externalRedis.host | quote }}
Expand All @@ -394,22 +416,20 @@ rabbitmq-password
{{- define "snippet.redis.password.secret.name" -}}
{{- if and (not .Values.redis.enabled) .Values.externalRedis.password -}}
{{ include "oncall.fullname" . }}-redis-external
{{- else if and (not .Values.redis.enabled) .Values.externalRedis.existingSecret -}}
{{ .Values.externalRedis.existingSecret }}
{{- else -}}
{{ include "oncall.redis.fullname" . }}
{{- end -}}
{{- end -}}

{{- define "snippet.redis.env" -}}
- name: REDIS_HOST
value: {{ include "snippet.redis.host" . }}
- name: REDIS_PORT
value: "6379"
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "snippet.redis.password.secret.name" . }}
key: redis-password
{{- end }}
{{- define "snippet.redis.password.secret.key" -}}
{{- if and (not .Values.redis.enabled) .Values.externalRedis.passwordKey -}}
{{ .Values.externalRedis.passwordKey }}
{{- else -}}
redis-password
{{- end -}}
{{- end -}}

{{- define "snippet.oncall.smtp.env" -}}
{{- if .Values.oncall.smtp.enabled -}}
Expand Down
8 changes: 4 additions & 4 deletions helm/oncall/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ data:
{{ template "snippet.oncall.secret.mirageSecretKey" . }}: {{ randAlphaNum 40 | b64enc | quote }}
{{- end }}
---
{{ if and (not .Values.mariadb.enabled) (eq .Values.database.type "mysql") -}}
{{ if and (not .Values.mariadb.enabled) (eq .Values.database.type "mysql") (not .Values.externalMysql.existingSecret) -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "oncall.fullname" . }}-mysql-external
type: Opaque
data:
mariadb-root-password: {{ required "externalMysql.password is required if not mariadb.enabled" .Values.externalMysql.password | b64enc | quote }}
mariadb-root-password: {{ required "externalMysql.password is required if not mariadb.enabled and not externalMysql.existingSecret" .Values.externalMysql.password | b64enc | quote }}
{{- end }}
---
{{ if and (eq .Values.broker.type "rabbitmq") (not .Values.rabbitmq.enabled) (not .Values.externalRabbitmq.existingSecret) -}}
Expand All @@ -31,14 +31,14 @@ data:
rabbitmq-password: {{ required "externalRabbitmq.password is required if not rabbitmq.enabled and not externalRabbitmq.existingSecret" .Values.externalRabbitmq.password | b64enc | quote }}
{{- end }}
---
{{ if not .Values.redis.enabled -}}
{{ if and (not .Values.redis.enabled) (not .Values.externalRedis.existingSecret) -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "oncall.fullname" . }}-redis-external
type: Opaque
data:
redis-password: {{ required "externalRedis.password is required if not redis.enabled" .Values.externalRedis.password | b64enc | quote }}
redis-password: {{ required "externalRedis.password is required if not redis.enabled and not externalRedis.existingSecret" .Values.externalRedis.password | b64enc | quote }}
{{- end }}
---
{{ if and .Values.oncall.smtp.enabled .Values.oncall.smtp.password -}}
Expand Down
8 changes: 8 additions & 0 deletions helm/oncall/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ externalMysql:
db_name:
user:
password:
# use an existing secret for the database password
existingSecret: ""
# the key in the secret containing the database password
passwordKey: ""

# PostgreSQL is included into this release for the convenience.
# It is recommended to host it separately from this release
Expand Down Expand Up @@ -280,6 +284,10 @@ redis:
externalRedis:
host:
password:
# use an existing secret for the redis password
existingSecret: ""
# the key in the secret containing the redis password
passwordKey: ""

# Grafana is included into this release for the convenience.
# It is recommended to host it separately from this release
Expand Down

0 comments on commit 91a9cb3

Please sign in to comment.