zar*_*ski 18 yaml templating go-templates kubernetes-helm
说我有这些价值观
grafana:
...
ingress:
enabled: true
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: ["/grafana"]
Run Code Online (Sandbox Code Playgroud)
这是标准的头盔。出于这个原因,我想保留hosts为一个数组(即使它使接下来的移动有点棘手)。我怎样才能获得第一个.host(我不介意任何可能的其他)才能使env.value动态
containers:
- name: {{ .Chart.Name }}-grafana
env:
- name: GF_DOMAIN
value: chart-example.local
Run Code Online (Sandbox Code Playgroud)
我试过
env:
- name: GF_DOMAIN
{{- range .Values.grafana.ingress.hosts }}
value: {{ .host }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)
env:
{{- range .Values.grafana.ingress.hosts }}
- name: GF_DOMAIN
value: {{ .host }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)
按照这个建议,我也尝试过
env:
{{- with .Values.grafana.ingress.hosts 0}}
- name: GF_DOMAIN
value: {{ .host }}
{{- end}}
Run Code Online (Sandbox Code Playgroud)
或者
value: {{ .Values.grafana.ingress.hosts 0 .host }}
value: {{ .Values.grafana.ingress.hosts | first.host}}
Run Code Online (Sandbox Code Playgroud)
我该如何处理这个案子?
Lau*_*ela 41
你需要的是这个index功能:
env:
{{- with (index .Values.grafana.ingress.hosts 0) }}
- name: GF_DOMAIN
value: {{ .host }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)
或者,first也可以工作:
env:
{{- with (first .Values.grafana.ingress.hosts) }}
- name: GF_DOMAIN
value: {{ .host }}
{{- end }}
Run Code Online (Sandbox Code Playgroud)