@@ -74,37 +74,51 @@ Return the fully qualified startup jitter image reference.
7474{{- end -}}
7575
7676{{/*
77- Joins a list of strings with "-" and makes the result safe for use as a
78- Kubernetes resource name (lowercase, no special chars, max 63 chars).
77+ Given a list of strings, concatenate all of them with a dash ("-")
78+ and slugify the string to be DNS name compatible
79+ */ }}
80+ {{- define " com.klicktipp.slugify-volume-name" -}}
81+ {{- $r := (join " -" . ) | lower | replace " ." " -" | replace " /" " -" | replace " _" " -" | replace " --" " -" | replace " " " -" | trimPrefix " -" | trunc 63 | trimSuffix " -" }}
82+ {{- $r }}
83+ {{- end -}}
84+
85+ {{/*
86+ Collision-free PV / PVC names. Accepts the same list as slugify-volume-name:
87+ [prefix, infix..., suffix]
88+ prefix – first element (namespace for PVs, release name for PVCs); kept as-is
89+ infix – all middle elements; joined and sha256-hashed to 8 hex chars
90+ suffix – last element (EFS access-point ID without "fsap-" prefix); kept as-is
7991
80- The last element is always kept in full — it is the unique part (e.g. an EFS
81- access point ID like "0e702cdce44153d31"). If the combined string would exceed
82- 63 chars, the prefix (everything before the last element) is shortened from the
83- right to make room. This way two different access points for the same job always
84- get two different PV names, even in namespaces with long names.
92+ Result: prefix-hash(infix)-suffix (≤ 63 chars)
8593
86- Without this fix, the entire string was cut off at 63 chars from the right,
87- which silently dropped the access point ID for long namespace names, making
88- every access point of a job produce the same PV name — causing Kubernetes to
89- reject the update because the PV's volume source is immutable after creation.
94+ When the result would exceed 63 chars the prefix is right-truncated to fit;
95+ any trailing dash introduced by truncation is stripped.
96+
97+ Because the hash covers the full infix and the access-point ID sits verbatim in
98+ the suffix, names are globally unique even if the same access point is mounted
99+ more than once or two jobs share the same name prefix.
100+
101+ Enable per release with .Values.slugifyVolumeNamesV2: true.
90102*/ }}
91- {{- define " com.klicktipp.slugify-volume-name" -}}
92- {{- if and (kindIs " slice" . ) (gt (len . ) 1) -}}
93- {{- $last := last . | lower | replace " ." " -" | replace " /" " -" | replace " _" " -" | replace " --" " -" | replace " " " -" | trimPrefix " -" | trimSuffix " -" -}}
94- {{- if ge (len $last ) 63 -}}
95- {{- $last | trunc 63 | trimSuffix " -" | trimPrefix " -" -}}
103+ {{- define " com.klicktipp.slugify-volume-name-v2" -}}
104+ {{- $first := first . | lower | replace " ." " -" | replace " /" " -" | replace " _" " -" | replace " --" " -" | replace " " " -" | trimPrefix " -" | trimSuffix " -" -}}
105+ {{- $last := last . | lower | replace " ." " -" | replace " /" " -" | replace " _" " -" | replace " --" " -" | replace " " " -" | trimPrefix " -" | trimSuffix " -" -}}
106+ {{- $hash := join " -" (rest (initial . )) | sha256sum | trunc 8 -}}
107+ {{- $result := printf " %s -%s -%s " $first $hash $last -}}
108+ {{- if le (len $result ) 63 -}}
109+ {{- $result -}}
110+ {{- else -}}
111+ {{- $max := int (sub 53 (len $last )) -}}
112+ {{- if le $max 0 -}}
113+ {{- printf " %s -%s " $hash $last | trunc 63 | trimSuffix " -" -}}
96114{{- else -}}
97- {{- $prefix := join " -" (initial . ) | lower | replace " ." " -" | replace " /" " -" | replace " _" " -" | replace " --" " -" | replace " " " -" | trimPrefix " -" | trimSuffix " -" -}}
98- {{- $max := int (sub 63 (add 1 (len $last ))) -}}
99- {{- $p := $prefix | trunc $max | trimSuffix " -" | trimPrefix " -" -}}
100- {{- if eq $p " " -}}
101- {{- $last -}}
115+ {{- $f := $first | trunc $max | trimSuffix " -" | trimPrefix " -" -}}
116+ {{- if eq $f " " -}}
117+ {{- printf " %s -%s " $hash $last -}}
102118{{- else -}}
103- {{- printf " %s -%s " $p $last | trimSuffix " - " -}}
119+ {{- printf " %s -%s - %s " $f $hash $last -}}
104120{{- end -}}
105121{{- end -}}
106- {{- else -}}
107- {{- (join " -" . ) | lower | replace " ." " -" | replace " /" " -" | replace " _" " -" | replace " --" " -" | replace " " " -" | trimPrefix " -" | trunc 63 | trimSuffix " -" -}}
108122{{- end -}}
109123{{- end -}}
110124
0 commit comments