Fixing robustName to allow '.'

This commit is contained in:
Laszlo Fogas
2021-03-02 11:05:43 +01:00
parent d74caba3ee
commit 3b99ad506d
4 changed files with 40 additions and 5 deletions
+1 -1
View File
@@ -68,5 +68,5 @@ Create robustName that can be used as Kubernetes resource name, and as subdomain
\W all but \w .
*/}}
{{- define "robustName" -}}
{{ regexReplaceAll "\\W+" . "-" | replace "_" "-" | lower | trunc 63 | trimSuffix "-" }}
{{ regexReplaceAll "[^0-9A-Za-z_\\.]+" . "-" | replace "_" "-" | lower | trunc 63 | trimSuffix "-" | trimPrefix "-" }}
{{- end }}
+4 -3
View File
@@ -1,6 +1,7 @@
{{- $labels := include "helm-chart.labels" . -}}
{{- with .Values.ingress -}}
{{- $robustName := include "robustName" $.Release.Name -}}
{{- if semverCompare ">=1.14-0" $.Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
@@ -8,7 +9,7 @@ apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ template "robustName" $.Release.Name }}
name: {{ $robustName }}
namespace: {{ $.Release.Namespace }}
labels:
{{- $labels | nindent 4 }}
@@ -20,8 +21,8 @@ spec:
{{- if default false .tlsEnabled }}
tls:
- hosts:
- {{ .host | quote }}
secretName: {{ printf "tls-%s" $.Release.Name }}
- {{ template "robustName" .host | quote }}
secretName: {{ printf "tls-%s" $robustName }}
{{- end }}
rules:
- host: {{ template "robustName" .host | quote }}
+31 -1
View File
@@ -13,7 +13,37 @@ tests:
value:
- hosts:
- chart-example.local
secretName: tls-RELEASE-NAME
secretName: tls-release-name
- equal:
path: spec.rules
value:
- host: chart-example.local
http:
paths:
- backend:
serviceName: release-name
servicePort: 80
- it: Should conform to DNS names
set:
ingress:
host: feature/my_branch.local
tlsEnabled: true
asserts:
- equal:
path: spec.tls
value:
- hosts:
- feature-my-branch.local
secretName: tls-release-name
- equal:
path: spec.rules
value:
- host: feature-my-branch.local
http:
paths:
- backend:
serviceName: release-name
servicePort: 80
- it: Should set Ingress annotation
set:
ingress: