替换 helm 图表中标签的命令
Replaces command for label in helm charts
我经常在 helm 图表中看到以下片段:
labels:
app: {{ template "app.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
为什么需要更换? +
迹象不好吗?
根据此 (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()
returns 将输入字符串中所有出现的给定子字符串替换为另一个子字符串后的字符串。该函数是非递归的,从左到右运行。
语法:
替换(文本,from_str,to_str)
Return数据类型:字符串
pod 配置文件中的有效标签值必须为 63 个字符或更少,并且必须为空或以字母数字字符 ([a-z0-9A-Z])
开头和结尾,其中包含破折号 (-)
、下划线 (_)
、点 (.)
和字母数字之间。
replace "+" "_"
将加号字符替换为下划线。这就是我们避免失败的方式。
您可以在此处找到更多信息:replace-chart, syntax-pod-label。
我经常在 helm 图表中看到以下片段:
labels:
app: {{ template "app.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
为什么需要更换? +
迹象不好吗?
根据此 (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()
returns 将输入字符串中所有出现的给定子字符串替换为另一个子字符串后的字符串。该函数是非递归的,从左到右运行。
语法:
替换(文本,from_str,to_str) Return数据类型:字符串
pod 配置文件中的有效标签值必须为 63 个字符或更少,并且必须为空或以字母数字字符 ([a-z0-9A-Z])
开头和结尾,其中包含破折号 (-)
、下划线 (_)
、点 (.)
和字母数字之间。
replace "+" "_"
将加号字符替换为下划线。这就是我们避免失败的方式。
您可以在此处找到更多信息:replace-chart, syntax-pod-label。