diff --git a/charts/sliding-sync-proxy/templates/deployment.yaml b/charts/sliding-sync-proxy/templates/deployment.yaml index c06409e..a5743be 100644 --- a/charts/sliding-sync-proxy/templates/deployment.yaml +++ b/charts/sliding-sync-proxy/templates/deployment.yaml @@ -28,6 +28,24 @@ spec: {{- end }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.initContainers }} + initContainers: + {{- $initContainers := list }} + {{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }} + {{- $container := get $.Values.initContainers $key }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $key }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}} + {{- $newEnv := fromYaml (include "lib.container.envVars" $) -}} + {{- $_ := unset $.ObjectValues "envVars" -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- end }} + {{- $initContainers = append $initContainers $container }} + {{- end }} + {{- tpl (toYaml $initContainers) $ | nindent 8 }} + {{- end }} containers: - name: {{ .Chart.Name }} securityContext: diff --git a/charts/sliding-sync-proxy/templates/lib/container/_env_vars.tpl b/charts/sliding-sync-proxy/templates/lib/container/_env_vars.tpl new file mode 100644 index 0000000..c602dec --- /dev/null +++ b/charts/sliding-sync-proxy/templates/lib/container/_env_vars.tpl @@ -0,0 +1,43 @@ +{{/* +Environment variables used by containers. +*/}} +{{- define "lib.container.envVars" -}} + {{- $values := .Values.env -}} + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.envVars -}} + {{- $values = . -}} + {{- end -}} + {{- end -}} + + {{- with $values -}} + {{- $result := list -}} + {{- range $k, $v := . -}} + {{- $name := $k -}} + {{- $value := $v -}} + {{- if kindIs "int" $name -}} + {{- $name = required "environment variables as a list of maps require a name field" $value.name -}} + {{- end -}} + + {{- if kindIs "map" $value -}} + {{- if hasKey $value "value" -}} + {{- $envValue := $value.value | toString -}} + {{- $result = append $result (dict "name" $name "value" (tpl $envValue $)) -}} + {{- else if hasKey $value "valueFrom" -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value.valueFrom) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value) -}} + {{- end -}} + {{- end -}} + {{- if not (kindIs "map" $value) -}} + {{- if kindIs "string" $value -}} + {{- $result = append $result (dict "name" $name "value" (tpl $value $)) -}} + {{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}} + {{- $result = append $result (dict "name" $name "value" ($value | toString)) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "value" $value) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- toYaml (dict "env" $result) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/sliding-sync-proxy/values.yaml b/charts/sliding-sync-proxy/values.yaml index 264998a..bb7fb1e 100644 --- a/charts/sliding-sync-proxy/values.yaml +++ b/charts/sliding-sync-proxy/values.yaml @@ -17,6 +17,15 @@ extraEnv: {} # SYNCV3_DEBUG: "true" imagePullSecrets: [] +#initContainers: +# 01-init-db: +# image: ghcr.io/onedr0p/postgres-init:14.9 +# imagePullPolicy: IfNotPresent +# envFrom: &envFrom +# - configMapRef: +# name: &configMap synapse-configmap +# - secretRef: +# name: &secret synapse-secret nameOverride: "" fullnameOverride: ""