Files
truecharts/library/common/templates/classes/ingress/_ingressRoute.tpl
T
Kjeld Schouten-Lebbing 1257de6408 ExternalService and Entrypoint-Disable Support (#256)
* Setup externalService processing and enhance Traefik

* Simplify Ingress

* Simplify External Services

* Adjust Service and Portal settings accordingly

* Fix some newly introduced bugs

* Adapt docs
2021-03-12 16:56:04 +01:00

106 lines
3.0 KiB
Smarty

{{/*
This template serves as a blueprint for all ingressRoute objects that are created
within the common library.
*/}}
{{- define "common.classes.ingressRoute" -}}
{{- $ingressName := include "common.names.fullname" . -}}
{{- $values := .Values -}}
{{- $svcPort := 80 }}
{{- $portProtocol := "" }}
{{- $ingressService := $.Values }}
{{- if hasKey . "ObjectValues" -}}
{{- with .ObjectValues.ingress -}}
{{- $values = . -}}
{{- end -}}
{{ end -}}
{{- if hasKey $values "nameSuffix" -}}
{{- $ingressName = printf "%v-%v" $ingressName $values.nameSuffix -}}
{{- if and ( $.Values.services ) ( not $values.servicePort ) }}
{{- $ingressService := index $.Values.services ( $values.nameSuffix | quote) }}
{{- $svcPort = $ingressService.port.port }}
{{- $portProtocol = $ingressService.port.protocol | default "" }}
{{ end -}}
{{- else if and ( $.Values.services ) ( not $values.servicePort ) }}
{{- $svcPort = $.Values.services.main.port.port }}
{{- $portProtocol = $.Values.services.main.port.protocol | default "" }}
{{ end -}}
{{- $svcName := $values.serviceName | default $ingressName -}}
{{- if $values.servicePort }}
{{- $svcPort = $values.servicePort }}
{{- end }}
{{- if $values.serviceType }}
{{- $portProtocol = $values.serviceType }}
{{- end }}
apiVersion: traefik.containo.us/v1alpha1
{{- if eq $values.type "UDP" }}
kind: IngressRouteUDP
{{- else if eq $values.type "TCP" }}
kind: IngressRouteTCP
{{- else }}
kind: IngressRoute
{{- end }}
metadata:
name: {{ $ingressName }}
labels:
{{- include "common.labels" . | nindent 4 }}
annotations:
{{- with $values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
entryPoints:
- {{ $values.entrypoint }}
routes:
{{- if eq $values.type "UDP" }}
- services:
- name: {{ $svcName }}
port: {{ $svcPort }}
weight: 10
{{- else if eq $values.type "TCP" }}
- match: HostSNI(`*`)
services:
- name: {{ $svcName }}
port: {{ $svcPort }}
weight: 10
terminationDelay: 400
{{- else }}
- kind: Rule
match: Host(`{{ (index $values.hosts 0).host }}`) && PathPrefix(`{{ (index $values.hosts 0).path | default "/" }}`)
services:
- name: {{ $svcName }}
{{- if $values.serviceKind }}
kind: {{ $values.serviceKind }}
{{- else }}
port: {{ $svcPort }}
{{- end }}
middlewares:
- name: traefik-middlewares-chain-public@kubernetescrd
{{- if $values.authForwardURL }}
- name: "{{ $ingressName }}-auth-forward"
{{- end }}
{{- end }}
{{- if not ( eq $values.type "UDP" ) }}
{{- if or ( eq $values.certType "selfsigned") (eq $values.certType "ixcert") }}
tls:
domains:
- main: {{ (index $values.hosts 0).host }}
sans:
{{- range $values.hosts }}
- {{ .host | quote }}
{{- end }}
{{- if eq $values.certType "ixcert" }}
secretName: {{ $ingressName }}
{{- end }}
passthrough: false
{{- end }}
{{- end }}
{{- end }}