Helm Conditional Templates

五迷三道 提交于 2021-01-02 05:37:09

问题


I found that we can create subcharts and conditionally include them as described here: Helm conditionally install subchart

I have just one template that I want conditionally include in my chart but I could not find anything in the docs. Is there such feature?


回答1:


I discovered that empty templates are not loaded. I solved it by wrapping my yaml file content in an if condition.

{{ if .Values.something }}
content of yaml file
{{ end }}



回答2:


You simply wrap the template resource at the first and last lines with the check you want to do. Let's take the official Grafana chart as example:

In its values.yaml, it has a flag called ingress.enabled, which looks like the following:

ingress:
  enabled: false

Then in its ingress template resource, this flag is checked:

{{- if .Values.ingress.enabled -}}
...
apiVersion: extensions/v1beta1
kind: Ingress
...
{{- end }}

As a result, ingress object will only be created if ingress.enabled is set to true.



来源:https://stackoverflow.com/questions/57878785/helm-conditional-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!