Reputation: 772
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?
Upvotes: 3
Views: 4724
Reputation: 7023
Replace - script and chart function
Replace()
returns a string after replacing all occurrences of a given substring within the input string with another substring. The function is non-recursive and works from left to right.
Syntax:
Replace(text, from_str, to_str) Return data type: string
Valid label values in pod configuration file must be 63 characters or less and must be empty or begin and end with an alphanumeric character ([a-z0-9A-Z])
with dashes (-)
, underscores (_)
, dots (.)
, and alphanumerics between.
replace "+" "_"
replaces plus characters with underscores. And that is how we avoid failures.
More information you can find here: replace-chart, syntax-pod-label.
Upvotes: 2
Reputation: 904
As per this (https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set) documentation, labels cannot have plus(+) character in its value.
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.
Upvotes: 4