Skip to content

Commit 180b726

Browse files
reixdRainer 'rei' Schuth
andauthored
Rabbitmq cluster: Improve slugify function (#36)
Co-authored-by: Rainer 'rei' Schuth <rainer.schuth@digital-results-international.com>
1 parent 82b79d7 commit 180b726

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

charts/rabbitmq-cluster/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: v2
33
name: rabbitmq-cluster
44
description: Helm chart to define a RabbitMQ cluster via official rabbitmq.com CRDs (RabbitmqCluster).
55
type: application
6-
version: "2.3.0"
6+
version: "2.3.1"
77
appVersion: "4.2-management"
88
kubeVersion: ">= 1.33.0-0"
99
home: https://www.rabbitmq.com/kubernetes/operator/operator-overview.html

charts/rabbitmq-cluster/templates/_klicktipp.tpl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
slugify the string to be (k8s) DNS name compatible
44
*/}}
55
{{- define "com.klicktipp.slugify-string" -}}
6-
{{- $r := . | lower | replace "." "-" | replace "/" "-" | replace "_" "-" | replace " " "-" | replace "--" "-" | trimPrefix "-" | trunc 63 | trimSuffix "-" }}
7-
{{- $r }}
6+
{{- /* 1) Make sure we’re working with a string, and lowercase it */ -}}
7+
{{- $text := . | toString | lower -}}
8+
9+
{{- /* 2) Replace “anything that is NOT a-z or 0-9” (in runs) with a dash */ -}}
10+
{{- $text = regexReplaceAll "[^a-z0-9]+" $text "-" -}}
11+
12+
{{- /* 3) Remove dashes at the start or end */ -}}
13+
{{- $text = trimAll "-" $text -}}
14+
15+
{{- /* 4) Limit to 63 characters, then remove a trailing dash if truncation created one */ -}}
16+
{{- $text = $text | trunc 63 | trimSuffix "-" -}}
17+
18+
{{- /* Step 5: If nothing is left (e.g. input was only symbols), fail fast */ -}}
19+
{{- if eq $text "" -}}
20+
{{- fail "slugify: input became empty after sanitizing (must contain at least one a-z/0-9)" -}}
21+
{{- end -}}
22+
23+
{{- /* Final: output the slug */ -}}
24+
{{- $text -}}
825
{{- end -}}

0 commit comments

Comments
 (0)