Skip to content

Commit

Permalink
ci: PLT-367: Allow templates in values.yaml files (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
farioas authored Jun 28, 2024
1 parent 7c55c26 commit 2129a8c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
4 changes: 4 additions & 0 deletions heartex/label-studio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.5.0
### Improvements
* Add support for template variables in helm values.

## 1.4.11
### Improvements
* Reset resources for uwsgiExporter container.
Expand Down
55 changes: 34 additions & 21 deletions heartex/label-studio/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ Set's common environment variables
{{- else }}
{{- if .Values.global.pgConfig.dbName }}
- name: POSTGRE_NAME
value: {{ .Values.global.pgConfig.dbName }}
value: {{ include "render-values" ( dict "value" .Values.global.pgConfig.dbName "context" $) }}
{{- end }}
{{- end }}
{{- if .Values.global.pgConfig.host }}
- name: POSTGRE_HOST
value: {{ .Values.global.pgConfig.host }}
value: {{ include "render-values" ( dict "value" .Values.global.pgConfig.host "context" $) }}
{{- else }}
{{- if .Values.postgresql.enabled }}
- name: POSTGRE_HOST
Expand All @@ -275,30 +275,30 @@ Set's common environment variables
value: {{ .Values.global.pgConfig.port | quote }}
{{- end }}
{{- end }}
{{- if (and .Values.postgresql.enabled .Values.postgresql.auth.username) }}
{{- if .Values.global.pgConfig.userName }}
- name: POSTGRE_USER
value: {{ .Values.postgresql.auth.username}}
value: {{ include "render-values" ( dict "value" .Values.global.pgConfig.userName "context" $) }}
{{- else }}
{{- if .Values.global.pgConfig.userName }}
{{- if (and .Values.postgresql.enabled .Values.postgresql.auth.username) }}
- name: POSTGRE_USER
value: {{ .Values.global.pgConfig.userName }}
value: {{ .Values.postgresql.auth.username}}
{{- end }}
{{- end }}
{{- if (and .Values.postgresql.enabled .Values.postgresql.auth.password) }}
- name: POSTGRE_PASSWORD
value: {{ .Values.postgresql.auth.password }}
{{- else }}
{{- if (and .Values.global.pgConfig.password.secretName .Values.global.pgConfig.password.secretKey) }}
- name: POSTGRE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.global.pgConfig.password.secretName }}
key: {{ .Values.global.pgConfig.password.secretKey }}
name: {{ include "render-values" ( dict "value" .Values.global.pgConfig.password.secretName "context" $) }}
key: {{ include "render-values" ( dict "value" .Values.global.pgConfig.password.secretKey "context" $) }}
{{- else }}
{{- if (and .Values.postgresql.enabled .Values.postgresql.auth.password) }}
- name: POSTGRE_PASSWORD
value: {{ .Values.postgresql.auth.password }}
{{- end }}
{{- end }}
{{- if .Values.global.redisConfig.host }}
- name: REDIS_LOCATION
value: {{ .Values.global.redisConfig.host }}
value: {{ include "render-values" ( dict "value" .Values.global.redisConfig.host "context" $) }}
{{- else }}
{{- if .Values.redis.enabled }}
- name: REDIS_LOCATION
Expand All @@ -319,8 +319,8 @@ Set's common environment variables
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.global.redisConfig.password.secretName }}
key: {{ .Values.global.redisConfig.password.secretKey }}
name: {{ include "render-values" ( dict "value" .Values.global.redisConfig.password.secretName "context" $) }}
key: {{ include "render-values" ( dict "value" .Values.global.redisConfig.password.secretKey "context" $) }}
{{- end }}
{{- end }}
- name: PYTHONUNBUFFERED
Expand Down Expand Up @@ -457,15 +457,15 @@ Set's common environment variables
{{- end }}
{{- if .Values.global.pgConfig.ssl.pgSslRootCertSecretKey }}
- name: POSTGRE_SSLROOTCERT
value: "/opt/heartex/secrets/pg_certs/{{ .Values.global.pgConfig.ssl.pgSslRootCertSecretKey }}"
value: "/opt/heartex/secrets/pg_certs/{{ include "render-values" ( dict "value" .Values.global.pgConfig.ssl.pgSslRootCertSecretKey "context" $) }}"
{{- end }}
{{- if .Values.global.pgConfig.ssl.pgSslCertSecretKey }}
- name: POSTGRE_SSLCERT
value: "/opt/heartex/secrets/pg_certs/{{ .Values.global.pgConfig.ssl.pgSslCertSecretKey }}"
value: "/opt/heartex/secrets/pg_certs/{{ include "render-values" ( dict "value" .Values.global.pgConfig.ssl.pgSslCertSecretKey "context" $) }}"
{{- end }}
{{- if .Values.global.pgConfig.ssl.pgSslKeySecretKey }}
- name: POSTGRE_SSLKEY
value: "/opt/heartex/secrets/pg_certs/{{ .Values.global.pgConfig.ssl.pgSslKeySecretKey }}"
value: "/opt/heartex/secrets/pg_certs/{{ include "render-values" ( dict "value" .Values.global.pgConfig.ssl.pgSslKeySecretKey "context" $) }}"
{{- end }}
{{- if .Values.global.redisConfig.ssl.redisSslCertReqs }}
- name: REDIS_SSL_CERTS_REQS
Expand All @@ -475,15 +475,15 @@ Set's common environment variables
{{- end }}
{{- if .Values.global.redisConfig.ssl.redisSslCaCertsSecretKey }}
- name: REDIS_SSL_CA_CERTS
value: "/opt/heartex/secrets/redis_certs/{{ .Values.global.redisConfig.ssl.redisSslCaCertsSecretKey }}"
value: "/opt/heartex/secrets/redis_certs/{{ include "render-values" ( dict "value" .Values.global.redisConfig.ssl.redisSslCaCertsSecretKey "context" $) }}"
{{- end }}
{{- if .Values.global.redisConfig.ssl.redisSslCertFileSecretKey }}
- name: REDIS_SSL_CERTFILE
value: "/opt/heartex/secrets/redis_certs/{{ .Values.global.redisConfig.ssl.redisSslCertFileSecretKey }}"
value: "/opt/heartex/secrets/redis_certs/{{ include "render-values" ( dict "value" .Values.global.redisConfig.ssl.redisSslCertFileSecretKey "context" $) }}"
{{- end }}
{{- if .Values.global.redisConfig.ssl.redisSslKeyFileSecretKey }}
- name: REDIS_SSL_KEYFILE
value: "/opt/heartex/secrets/redis_certs/{{ .Values.global.redisConfig.ssl.redisSslKeyFileSecretKey }}"
value: "/opt/heartex/secrets/redis_certs/{{ include "render-values" ( dict "value" .Values.global.redisConfig.ssl.redisSslKeyFileSecretKey "context" $) }}"
{{- end }}
{{- if .Values.global.envInjectSources }}
- name: ENV_INJECT_SOURCES
Expand Down Expand Up @@ -525,4 +525,17 @@ Set's common environment variables
{{- else -}}
{{- print "batch/v1" -}}
{{- end -}}
{{- end -}}
{{/*
Renders a value that contains template.
Usage:
{{ include "render-values" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "render-values" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
4 changes: 2 additions & 2 deletions heartex/label-studio/templates/app-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ spec:
{{- if .Values.global.pgConfig.ssl.pgSslSecretName }}
- name: pg-ssl-certs
secret:
secretName: {{ .Values.global.pgConfig.ssl.pgSslSecretName }}
secretName: {{ include "render-values" ( dict "value" .Values.global.pgConfig.ssl.pgSslSecretName "context" $) }}
defaultMode: 0640
{{- end }}
{{- if .Values.global.redisConfig.ssl.redisSslSecretName }}
- name: redis-ssl-certs
secret:
secretName: {{ .Values.global.redisConfig.ssl.redisSslSecretName }}
secretName: {{ include "render-values" ( dict "value" .Values.global.redisConfig.ssl.redisSslSecretName "context" $) }}
defaultMode: 0640
{{- end }}
{{- if .Values.app.extraVolumes -}}
Expand Down
4 changes: 2 additions & 2 deletions heartex/label-studio/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ spec:
{{- if $.Values.global.pgConfig.ssl.pgSslSecretName }}
- name: pg-ssl-certs
secret:
secretName: {{ $.Values.global.pgConfig.ssl.pgSslSecretName }}
secretName: {{ include "render-values" ( dict "value" $.Values.global.pgConfig.ssl.pgSslSecretName "context" $) }}
defaultMode: 0640
{{- end }}
{{- if $.Values.global.redisConfig.ssl.redisSslSecretName }}
- name: redis-ssl-certs
secret:
secretName: {{ $.Values.global.redisConfig.ssl.redisSslSecretName }}
secretName: {{ include "render-values" ( dict "value" $.Values.global.redisConfig.ssl.redisSslSecretName "context" $) }}
defaultMode: 0640
{{- end }}
{{- if $.Values.app.extraVolumes -}}
Expand Down
4 changes: 2 additions & 2 deletions heartex/label-studio/templates/rqworker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ spec:
{{- if $.Values.global.pgConfig.ssl.pgSslSecretName }}
- name: pg-ssl-certs
secret:
secretName: {{ $.Values.global.pgConfig.ssl.pgSslSecretName }}
secretName: {{ include "render-values" ( dict "value" $.Values.global.pgConfig.ssl.pgSslSecretName "context" $) }}
defaultMode: 0640
{{- end }}
{{- if $.Values.global.redisConfig.ssl.redisSslSecretName }}
- name: redis-ssl-certs
secret:
secretName: {{ $.Values.global.redisConfig.ssl.redisSslSecretName }}
secretName: {{ include "render-values" ( dict "value" $.Values.global.redisConfig.ssl.redisSslSecretName "context" $) }}
defaultMode: 0640
{{- end }}
{{- if $.Values.rqworker.extraVolumes -}}
Expand Down

0 comments on commit 2129a8c

Please sign in to comment.