use tpl less

This commit is contained in:
Stavros kois
2023-01-25 18:47:47 +02:00
parent 2bd5c11df0
commit cbab6726c3
2 changed files with 23 additions and 14 deletions
@@ -1,9 +1,5 @@
{{/*
A custom dict is expected with envList and root.
It's designed to work for mainContainer AND initContainers.
Calling this from an initContainer, wouldn't work, as it would have a different "root" context,
and "tpl" on "$" would cause erors.
That's why the custom dict is expected.
{{/* Call this template like this:
{{- include "ix.v1.common.container.envFrom" (dict "envFrom" $envFrom "root" $root "containerName" $containerName) -}}
*/}}
{{/* Environment Variables From included by the container */}}
@@ -12,17 +8,22 @@ That's why the custom dict is expected.
{{- $containerName := .containerName -}}
{{- $root := .root -}}
{{- $envDict := (dict "envs" $envFrom) -}}
{{- if $envFrom -}}
{{- $envFrom = (fromYaml (tpl ($envDict | toYaml) $root)).envs -}}
{{- end -}}
{{- range $envFrom -}}
{{- if and .secretRef .configMapRef -}}
{{- fail "You can't define both secretRef and configMapRef on the same item." -}}
{{- end -}}
{{- if .secretRef }}
{{- $secretName := (tpl (required "Name is required for secretRef in envFrom." .secretRef.name) $root) }}
{{- $secretName := required "Name is required for secretRef in envFrom." .secretRef.name }}
- secretRef:
name: {{ $secretName | quote }}
{{- include "ix.v1.common.util.storeEnvFromVarsForCheck" (dict "root" $root "containerName" $containerName "source" (printf "%s-%s" "secret" $secretName)) -}}
{{- else if .configMapRef }}
{{- $configName := (tpl (required "Name is required for configMapRef in envFrom." .configMapRef.name) $root) }}
{{- $configName := required "Name is required for configMapRef in envFrom." .configMapRef.name }}
- configMapRef:
name: {{ $configName | quote }}
{{- include "ix.v1.common.util.storeEnvFromVarsForCheck" (dict "root" $root "containerName" $containerName "source" (printf "%s-%s" "configmap" $configName)) -}}
@@ -106,17 +106,25 @@
{{- $root := .root -}}
{{- $item := .item -}}
{{- $name := .name -}}
{{/* We need to make sure that is always dict. With nested values.
Will be removed once the tpl is moved in upper level
*/}}
{{- $itemDict := (dict "item" $item) -}}
{{- if $item -}}
{{- $item = (fromYaml (tpl ($itemDict | toYaml) $root)).item -}}
{{- end -}}
{{- if not $item.mountPath -}} {{/* Make sure that we have a mountPath */}}
{{- fail "<mountPath> must be defined, alternatively use the <noMount> flag." -}}
{{- end -}}
{{- $mountPath := (tpl $item.mountPath $root) -}}
{{- if not (hasPrefix "/" $mountPath) -}}
{{- fail (printf "Mount path (%s), must start with a forward slash -> / <-" $mountPath) -}}
{{- if not (hasPrefix "/" $item.mountPath) -}}
{{- fail (printf "Mount path (%s), must start with a forward slash -> / <-" $item.mountPath) -}}
{{- end }}
- name: {{ tpl $name $root }}
mountPath: {{ $mountPath }}
mountPath: {{ $item.mountPath }}
{{- with $item.subPath }}
subPath: {{ tpl . $root }}
subPath: {{ . }}
{{- end -}}
{{- if (hasKey $item "readOnly") -}}
{{- if or (eq $item.readOnly true) (eq $item.readOnly false) }}
@@ -126,6 +134,6 @@
{{- end -}}
{{- end -}}
{{- with $item.mountPropagation }}
mountPropagation: {{ tpl . $root }}
mountPropagation: {{ . }}
{{- end -}}
{{- end -}}