簡體   English   中英

掌舵模板:如何將模板的結果分配給變量

[英]helm template: how do i assign the result of a template to a variable

我正在嘗試執行以下操作:

{{- $cassandrafullname := template "cassandra.fullname" . -}}

但我在試運行時收到此錯誤:

Error: UPGRADE FAILED: parse error in "cassandra/templates/service.yaml": template: cassandra/templates/service.yaml:1: unexpected <template> in command

我有這個問題的原因是因為我無法在一個范圍內使用template cassandra.fullname ,所以我試圖將該值放入一個變量中並在該范圍內使用它。 所以如果有一個解決方案,它也會被接受!

Helm 定義了一個與標准template相同include函數,除了它返回渲染的輸出而不是輸出它。 你應該能夠寫

{{- $cassandrafullname := include "cassandra.fullname" . -}}

不幸的是,這不適用於fromYaml ,因此您不能像往常一樣將 yaml 結構讀入管道操作。 一個比較大的缺點。 很多時候我需要將一個列表過濾到另一個列表中,但這對於 helm 來說似乎是不可能的:

{{- define "sometpl" -}}
- bla: dibla
- oki: doki
{{- end -}}
---
{{- $v := include "sometpl" . | fromYaml }}
some: {{- $v | toYaml | nindent 2 }}

會給

some:
  Error: 'error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array
    into Go value of type map[string]interface {}'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM