我在 yaml 中有一个像这样的舵图:
env:
- name: EmailHeader
value: {{ .Values.npsweb.email.support.header | quote }}
在我的值文件中,我有这样的:
npsweb:
email:
support:
header: <html><body><img src='https://nps.dev.nuancepowershare.com/smr/images/weblogo.png' alt='SMR LOGO' /><hr />
但它说Anchor lt;html><body><img is never used
。我试着在它周围加上双引号,但它仍然没有被选中。
这里有什么问题,我该如何解决?
答案 0 :(得分:1)
您需要明确引用该字符串。有几种方法可以做到这一点,因此请选择合适的方法:
header-with-single-quotes: '<.../>'
header-with-double-quotes: "<.../>"
header-as-block-scalar: |-
<html>...</html>
header-as-block-scalar-with-whitespace: |-
<html>
<body>
...
</body>
</html>
所有这些形式都是相同的,除了最后一个将包含嵌入的换行符和空格。 (因为你的值包含单引号,单引号形式会不太方便。)你也可以考虑 storing the HTML content in a file 并用 .Files.Get
读取它(尽管 Helm 不包含模板函数用于转义 HTML)。
您现有的 values.yaml
文件有什么问题? YAML 有 anchor 的概念;你可以给文档的一部分这样的标签,并从文档的其他地方引用它。值开头的“&”字符标记一个锚点,第一个空格之前的文本是该锚点的名称。
在 Kubernetes 中没有那么多,但在 Docker Compose 中,您会经常看到可重用的环境变量块:
# (This is a Docker Compose file, not Kubernetes, as a YAML example)
version: '3.8'
x-environment: &environment # <-- anchor
DB_HOST: db
services:
db: { image: postgres }
application:
build: .
environment: *environment # <-- reference to anchor
worker:
build: .
command: ./worker
environment: *environment # <-- same reference to anchor