Skip to content

Commit

Permalink
feat: add templating for ingress hostnames
Browse files Browse the repository at this point in the history
Such that templates can be set in the values and they will be properly executed
  • Loading branch information
tjorbo committed Sep 18, 2024
1 parent c05551c commit 8f45ca7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,21 @@ Check if external db and postgres are not used at the same time
{{- fail "no database is enabled database-userPasswordKey" }}
{{- end }}
{{- end }}

{{/*
Run tpl on an input value
Takes 2 input parameters as list
Parameter 1: $ (Root context, required by tpl)
Parameter 2: Value to run tpl on
*/}}
{{- define "terminfinder-backend.value-tpl" -}}
{{- $ := index . 0 }}
{{- $tpl := index . 1 -}}
{{- /* only call tpl if there is at least one template expression */ -}}
{{- if contains "{{" $tpl -}}
{{- tpl $tpl $ }}
{{- else -}}
{{- $tpl -}}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className }}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
Expand Down Expand Up @@ -32,14 +32,14 @@ spec:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
- {{ include "terminfinder-backend.value-tpl" (list $ .) | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
- host: {{ include "terminfinder-backend.value-tpl" (list $ .host) | quote }}
http:
paths:
{{- range .paths }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,22 @@ Create the name of the service account to use
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Run tpl on an input value
Takes 2 input parameters as list
Parameter 1: $ (Root context, required by tpl)
Parameter 2: Value to run tpl on
*/}}
{{- define "terminfinder-frontend.value-tpl" -}}
{{- $ := index . 0 }}
{{- $tpl := index . 1 -}}
{{- /* only call tpl if there is at least one template expression */ -}}
{{- if contains "{{" $tpl -}}
{{- tpl $tpl $ }}
{{- else -}}
{{- $tpl -}}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ spec:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
- {{ include "terminfinder-frontend.value-tpl" (list $ .) | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
- host: {{ include "terminfinder-frontend.value-tpl" (list $ .host) | quote }}
http:
paths:
{{- range .paths }}
Expand Down

0 comments on commit 8f45ca7

Please sign in to comment.