【发布时间】:2020-01-12 17:11:38
【问题描述】:
我可以从目录中生成ConfigMap,但它们不会翻译模板指令或值。以下是Release.Namespace 模板指令未在ConfigMap 中输出的示例。
.
|____Chart.yaml
|____charts
|____.helmignore
|____templates
| |____my-scripts.yaml
|____values.yaml
|____test-files
|____test1.txt
---
# templates/myscripts.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: my-scripts
namespace: {{ .Release.Namespace }}
data:
test.txt: |-
{{ .Files.Get "test-files/test1.txt" | indent 4}}
# test-files/test1.txt
test file
{{ .Release.Namespace }}
当我运行helm install . --dry-run --debug --namespace this-should-print 时,这是我得到的与我所期望的:
实际:
---
# Source: test/templates/my-scripts.yaml
# templates/myscripts.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: my-scripts
namespace: test
data:
test.txt: |-
# test-files/test1.txt
test file
{{ .Release.Namespace }}
预期:
---
# Source: test/templates/my-scripts.yaml
# templates/myscripts.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: my-scripts
namespace: test
data:
test.txt: |-
# test-files/test1.txt
test file
this-should-print
或者,我会对指定目录中的每个文件都以如下格式输出感兴趣:
<filename>: |-
<content>
【问题讨论】:
-
一个很好问的 SO 问题的好例子:关于您的输入的所有必要信息(目录结构、关键文件的内容)、您运行的命令、您得到的确切内容以及您所期望的内容。非常好!
-
快速提示,您可以运行
helm template而不是helm install --dry-run -
酷,感谢您的提示!
标签: kubernetes kubernetes-helm