Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart Template Guide: Confusing statement about unnecessary conditional #1697

Open
windmueller opened this issue Feb 27, 2025 · 2 comments
Open

Comments

@windmueller
Copy link

The section Flow Control of the Chart Template Guide has this listing:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- with .Values.favorite }}
  drink: {{ .drink | default "tea" | quote }}
  food: {{ .food | upper | quote }}
  {{- end }}

In the next paragraph it states:

Note that we removed the if conditional from the previous exercise because it is now unnecessary - the block after with only executes if the value of PIPELINE is not empty.

However, the now omitted conditional was:

  {{- if eq .Values.favorite.drink "coffee" }}
  mug: "true"
  {{- end }}

That statement does not check if the value is empty but if .drink matches "coffee".

Has the example been changed without modifying the text or am I missing something here?

In my opinion the example should now be:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  {{- with .Values.favorite }}
  drink: {{ .drink | default "tea" | quote }}
  food: {{ .food | upper | quote }}
  {{- if eq .drink "coffee" }}
  mug: true
  {{- end }}
  {{- end }}
@TerryHowe
Copy link
Contributor

What happens if .drink is not set? So many template engines, I don't know.

@windmueller
Copy link
Author

When .drink is not set, mug will not be rendered. But the same applies for "tea".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants