I often see the following snippet in the helm charts:
labels:
app: {{ template "app.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
Why is the replacement necessary? Are +
signs bad?
I often see the following snippet in the helm charts:
labels:
app: {{ template "app.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
Why is the replacement necessary? Are +
signs bad?
根据这个(https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set)文档,标签的值中不能有加号(+)字符。
The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between.
Replace - 脚本和图表函数
Replace()
在用另一个子字符串替换输入字符串中所有出现的给定子字符串后返回一个字符串。该函数是非递归的,从左到右工作。
句法:
Replace(text, from_str, to_str) 返回数据类型:字符串
pod 配置文件中的有效标签值必须为 63 个字符或更少,并且必须为空或以字母数字字符开头和结尾,其中([a-z0-9A-Z])
包含破折号(-)
、下划线(_)
、圆点(.)
和字母数字。
replace "+" "_"
用下划线替换加号字符。这就是我们避免失败的方式。
您可以在此处找到更多信息:replace-chart、syntax-pod-label。