From 4d63e1f84f45fbd66cb70e7148a9021772b534bb Mon Sep 17 00:00:00 2001 From: Lukas Eichler Date: Sat, 2 Jun 2018 13:05:46 +0200 Subject: [PATCH] Added documentation for the tpl function --- docs/charts_tips_and_tricks.md | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/charts_tips_and_tricks.md b/docs/charts_tips_and_tricks.md index 484d8b936..a83b44457 100644 --- a/docs/charts_tips_and_tricks.md +++ b/docs/charts_tips_and_tricks.md @@ -106,6 +106,43 @@ For example: The above will render the template when .Values.foo is defined, but will fail to render and exit when .Values.foo is undefined. +## Using the 'tpl' Function + +The `tpl` function allows developers to evaluate strings as templates inside a template. +This is useful to pass a template string as a value to a chart or render external configuration files. +Syntax: `{{ tpl TEMPLATE_STRING VALUES }}` + +Examples: +``` +# values +template: "{{ .Values.name }}" +name: "Tom" + +# template +{{ tpl .Values.template . }} + +# output +Tom +``` + +Rendering a external configuration file: +``` +# external configuration file conf/app.conf +firstName={{ .Values.firstName }} +lastName={{ .Values.lastName }} + +# values +firstName: Peter +lastName: Parker + +# template +{{ tpl (.Files.Get "conf/app.conf") . }} + +# output +firstName=Peter +lastName=Parker +``` + ## Creating Image Pull Secrets Image pull secrets are essentially a combination of _registry_, _username_, and _password_. You may need them in an application you are deploying, but to create them requires running _base64_ a couple of times. We can write a helper template to compose the Docker configuration file for use as the Secret's payload. Here is an example: