From 7a70459ca1913fcffeb374eca4446c5f97427da9 Mon Sep 17 00:00:00 2001 From: Alex Speaks Date: Fri, 1 Feb 2019 08:18:10 -0800 Subject: [PATCH] Fix incorrect flow example and improve operator documentation (#4919) * Fix incorrect flow example and improve operator documentation Signed-off-by: Alex * Use golang comment format Signed-off-by: Alex --- docs/chart_template_guide/control_structures.md | 2 +- .../functions_and_pipelines.md | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/chart_template_guide/control_structures.md b/docs/chart_template_guide/control_structures.md index 68820dfa7..e2f9ca89d 100644 --- a/docs/chart_template_guide/control_structures.md +++ b/docs/chart_template_guide/control_structures.md @@ -53,7 +53,7 @@ data: myvalue: "Hello World" drink: {{ .Values.favorite.drink | default "tea" | quote }} food: {{ .Values.favorite.food | upper | quote }} - {{ if and (.Values.favorite.drink) (eq .Values.favorite.drink "coffee") }}mug: true{{ end }} + {{ if and .Values.favorite.drink (eq .Values.favorite.drink "coffee") }}mug: true{{ end }} ``` Note that `.Values.favorite.drink` must be defined or else it will throw an error when comparing it to "coffee". Since we commented out `drink: coffee` in our last example, the output should not include a `mug: true` flag. But if we add that line back into our `values.yaml` file, the output should look like this: diff --git a/docs/chart_template_guide/functions_and_pipelines.md b/docs/chart_template_guide/functions_and_pipelines.md index fe9c92d6e..fe5a3c2b2 100644 --- a/docs/chart_template_guide/functions_and_pipelines.md +++ b/docs/chart_template_guide/functions_and_pipelines.md @@ -150,6 +150,19 @@ Template functions and pipelines are a powerful way to transform information and ## Operators are functions -For templates, the operators (`eq`, `ne`, `lt`, `gt`, `and`, `or` and so on) are all implemented as functions. In pipelines, operations can be grouped with parentheses (`(`, and `)`). +Operators are implemented as functions that return a boolean value. To use `eq`, `ne`, `lt`, `gt`, `and`, `or`, `not` etcetera place the operator at the front of the statement followed by its parameters just as you would a function. To chain multiple operations together, separate individual functions by surrounding them with paranthesis. + +```yaml +{{/* include the body of this if statement when the variable .Values.fooString exists and is set to "foo" */}} +{{ if and .Values.fooString (eq .Values.fooString "foo") }} + {{ ... }} +{{ end }} + + +{{/* do not include the body of this if statement because unset variables evaluate to false and .Values.setVariable was negated with the not function. */}} +{{ if or .Values.anUnsetVariable (not .Values.aSetVariable) }} + {{ ... }} +{{ end }} +``` Now we can turn from functions and pipelines to flow control with conditions, loops, and scope modifiers.