diff --git a/templates/_container.yaml b/templates/_container.yaml new file mode 100644 index 0000000..32e1fe0 --- /dev/null +++ b/templates/_container.yaml @@ -0,0 +1,15 @@ +{{/* vim: set filetype=mustache: */}} + +{{- define "common.container.tpl" -}} +name: {{ .Chart.Name }} +securityContext: + {{- toYaml .Values.securityContext | nindent 4 }} +image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" +imagePullPolicy: {{ .Values.image.pullPolicy }} +resources: + {{- toYaml .Values.resources | nindent 4 }} +{{- end -}} + +{{- define "common.container" -}} +{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.container.tpl") -}} +{{- end -}} diff --git a/templates/_utils.tpl b/templates/_utils.tpl new file mode 100644 index 0000000..f0c087a --- /dev/null +++ b/templates/_utils.tpl @@ -0,0 +1,34 @@ +{{/* vim: set filetype=mustache: */}} + +{{- /* +Merge one or more YAML templates and output the result. +This takes an list of values: +- the first item is the top context +- the rest items are template names of the templates, the former one will override the latter. +*/ -}} +{{- define "common.utils.merge" -}} +{{- $top := first . -}} +{{- $dest := dict -}} +{{- range (rest .) -}} + {{- $src := fromYaml (include . $top) | default (dict) -}} + {{- $dest = merge $dest $src -}} +{{- end -}} +{{- toYaml $dest -}} +{{- end -}} + +{{- /* +Flatten list of arguments before rendering the given template. +This takes an list of values: +- the first item is the template name to be rendered +- the second item is either an list of arguments or a single argument +- the rest items are the appended arguments +*/ -}} +{{- define "common.utils.flattenCall" -}} +{{- $tpl := first . -}} +{{- $args := index . 1 -}} +{{- if not (typeIs "[]interface {}" $args) -}} + {{- $args = list $args -}} +{{- end -}} +{{- $args = concat $args (slice . 2) -}} +{{- include $tpl $args -}} +{{- end -}}