`&`和`*`在Helm模板中分别表示什么?

huangapple go评论130阅读模式
英文:

What does & and * denote in a helm template?

问题

  1. & helm 模板中表示引用一个标签或值。
  2. * helm 模板中表示将一个标签或值展开为多个键值对。
英文:

What does & and * denote in a helm template?

https://github.com/SeleniumHQ/docker-selenium/blob/trunk/charts/selenium-grid/templates/chrome-node-deployment.yaml#L7

https://github.com/SeleniumHQ/docker-selenium/blob/trunk/charts/selenium-grid/templates/chrome-node-deployment.yaml#L25

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: {{ template "seleniumGrid.chromeNode.fullname" . }}
  5. namespace: {{ .Release.Namespace }}
  6. labels: &chrome_node_labels //**& here**
  7. app: selenium-chrome-node
  8. app.kubernetes.io/name: selenium-chrome-node
  9. {{- include "seleniumGrid.commonLabels" . | nindent 4 }}
  10. {{- with .Values.chromeNode.labels }}
  11. {{- toYaml . | nindent 4 }}
  12. {{- end }}
  13. {{- with .Values.customLabels }}
  14. {{- toYaml . | nindent 4 }}
  15. {{- end }}
  16. spec:
  17. replicas: {{ .Values.chromeNode.replicas }}
  18. selector:
  19. matchLabels:
  20. app: selenium-chrome-node
  21. app.kubernetes.io/instance: {{ .Release.Name }}
  22. template:
  23. metadata:
  24. labels: *chrome_node_labels // **star here **
  25. annotations:

答案1

得分: 1

这看起来像是使用了YAML锚点,但我记得如果直接在Helm模板中使用会导致错误。我猜他们可能在这里进行了第二次渲染,先解析了YAML。

YAML锚点

锚点和别名。这包括两个部分:

  • 锚点 & 用于定义一块配置

  • 别名 * 用于在其他地方引用该配置块

因此,在下面的示例中,我们使用 &build-test 来定义一个步骤实体,它包含了多行可重用的配置,然后使用别名 *build-test 进行引用。

  1. definitions:
  2. steps:
  3. - step: &build-test
  4. name: 构建和测试
  5. script:
  6. - mvn package
  7. artifacts:
  8. - target/**
  9. pipelines:
  10. branches:
  11. develop:
  12. - step: *build-test
  13. main:
  14. - step: *build-test

anchors-and-aliases

英文:

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.

YAML anchors

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.

  1. definitions:
  2. steps:
  3. - step: &build-test
  4. name: Build and test
  5. script:
  6. - mvn package
  7. artifacts:
  8. - target/**
  9. pipelines:
  10. branches:
  11. develop:
  12. - step: *build-test
  13. main:
  14. - step: *build-test

anchors-and-aliases

huangapple
  • 本文由 发表于 2023年3月1日 16:06:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定