英文:
What does & and * denote in a helm template?
问题
& 在 helm 模板中表示引用一个标签或值。
* 在 helm 模板中表示将一个标签或值展开为多个键值对。
英文:
What does & and * denote in a helm template?
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "seleniumGrid.chromeNode.fullname" . }}
namespace: {{ .Release.Namespace }}
labels: &chrome_node_labels //**& here**
app: selenium-chrome-node
app.kubernetes.io/name: selenium-chrome-node
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- with .Values.chromeNode.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.chromeNode.replicas }}
selector:
matchLabels:
app: selenium-chrome-node
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels: *chrome_node_labels // **star here **
annotations:
答案1
得分: 1
这看起来像是使用了YAML锚点,但我记得如果直接在Helm模板中使用会导致错误。我猜他们可能在这里进行了第二次渲染,先解析了YAML。
锚点和别名。这包括两个部分:
-
锚点
&
用于定义一块配置 -
别名
*
用于在其他地方引用该配置块
因此,在下面的示例中,我们使用 &build-test
来定义一个步骤实体,它包含了多行可重用的配置,然后使用别名 *build-test
进行引用。
definitions:
steps:
- step: &build-test
name: 构建和测试
script:
- mvn package
artifacts:
- target/**
pipelines:
branches:
develop:
- step: *build-test
main:
- step: *build-test
英文:
This looks like the usage of YAML anchors, but I remember it would result in an error if used directly in the Helm templates. I guess they might be doing a second rendering here, where the YAML is parsed first.
Anchors and aliases. There are 2 parts to this:
-
The anchor
&
which defines a chunk of configuration -
The alias
*
used to refer to that chunk elsewhere
So in the example below we use &build-test to define a step entity, which has several lines for reuse, and the alias *build-test to reuse it.
definitions:
steps:
- step: &build-test
name: Build and test
script:
- mvn package
artifacts:
- target/**
pipelines:
branches:
develop:
- step: *build-test
main:
- step: *build-test
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论