Skip to content

Commit a108360

Browse files
committed
Add ingress support
1 parent 085d9cb commit a108360

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed

charts/maildev/templates/NOTES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@
99
Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ include "maildev.fullname" . }}'
1010

1111
{{- end }}
12+
{{- if .Values.ingress.enabled -}}
13+
From outside the cluster, the server URL(s) are:
14+
{{- range .Values.ingress.hosts }}
15+
http://{{ . }}
16+
{{- end }}

charts/maildev/templates/_helpers.tpl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,41 @@ Create the name of the service account to use
6161
{{- default "default" .Values.serviceAccount.name }}
6262
{{- end }}
6363
{{- end }}
64+
65+
{{/*
66+
Get KubeVersion removing pre-release information.
67+
*/}}
68+
{{- define "maildev.kubeVersion" -}}
69+
{{- default .Capabilities.KubeVersion.Version (regexFind "v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version) -}}
70+
{{- end -}}
71+
72+
{{/*
73+
Return the appropriate apiVersion for ingress.
74+
*/}}
75+
{{- define "maildev.ingress.apiVersion" -}}
76+
{{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19.x" (include "maildev.kubeVersion" .)) -}}
77+
{{- print "networking.k8s.io/v1" -}}
78+
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
79+
{{- print "networking.k8s.io/v1beta1" -}}
80+
{{- else -}}
81+
{{- print "extensions/v1beta1" -}}
82+
{{- end -}}
83+
{{- end -}}
84+
{{/*
85+
Return if ingress is stable.
86+
*/}}
87+
{{- define "maildev.ingress.isStable" -}}
88+
{{- eq (include "maildev.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
89+
{{- end -}}
90+
{{/*
91+
Return if ingress supports ingressClassName.
92+
*/}}
93+
{{- define "maildev.ingress.supportsIngressClassName" -}}
94+
{{- or (eq (include "maildev.ingress.isStable" .) "true") (and (eq (include "maildev.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "maildev.kubeVersion" .))) -}}
95+
{{- end -}}
96+
{{/*
97+
Return if ingress supports pathType.
98+
*/}}
99+
{{- define "maildev.ingress.supportsPathType" -}}
100+
{{- or (eq (include "maildev.ingress.isStable" .) "true") (and (eq (include "maildev.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "maildev.kubeVersion" .))) -}}
101+
{{- end -}}

charts/maildev/templates/ingress.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $ingressApiIsStable := eq (include "maildev.ingress.isStable" .) "true" -}}
3+
{{- $ingressSupportsIngressClassName := eq (include "maildev.ingress.supportsIngressClassName" .) "true" -}}
4+
{{- $ingressSupportsPathType := eq (include "maildev.ingress.supportsPathType" .) "true" -}}
5+
{{- $fullName := include "maildev.fullname" . -}}
6+
{{- $serviceName := printf "%s-web" $fullName -}}
7+
{{- $servicePort := .Values.ports.web -}}
8+
{{- $ingressPath := .Values.ingress.path -}}
9+
{{- $ingressPathType := .Values.ingress.pathType -}}
10+
{{- $extraPaths := .Values.ingress.extraPaths -}}
11+
apiVersion: {{ include "maildev.ingress.apiVersion" . }}
12+
kind: Ingress
13+
metadata:
14+
name: {{ $fullName }}
15+
labels:
16+
{{- include "maildev.labels" . | nindent 4 }}
17+
{{- if .Values.ingress.labels }}
18+
{{ toYaml .Values.ingress.labels | indent 4 }}
19+
{{- end }}
20+
{{- if .Values.ingress.annotations }}
21+
annotations:
22+
{{- range $key, $value := .Values.ingress.annotations }}
23+
{{ $key }}: {{ tpl $value $ | quote }}
24+
{{- end }}
25+
{{- end }}
26+
spec:
27+
{{- if and $ingressSupportsIngressClassName .Values.ingress.ingressClassName }}
28+
ingressClassName: {{ .Values.ingress.ingressClassName }}
29+
{{- end -}}
30+
{{- if .Values.ingress.tls }}
31+
tls:
32+
{{ tpl (toYaml .Values.ingress.tls) $ | indent 4 }}
33+
{{- end }}
34+
rules:
35+
{{- if .Values.ingress.hosts }}
36+
{{- range .Values.ingress.hosts }}
37+
- host: {{ tpl . $}}
38+
http:
39+
paths:
40+
{{- if $extraPaths }}
41+
{{ toYaml $extraPaths | indent 10 }}
42+
{{- end }}
43+
- path: {{ $ingressPath }}
44+
{{- if $ingressSupportsPathType }}
45+
pathType: {{ $ingressPathType }}
46+
{{- end }}
47+
backend:
48+
{{- if $ingressApiIsStable }}
49+
service:
50+
name: {{ $serviceName }}
51+
port:
52+
number: {{ $servicePort }}
53+
{{- else }}
54+
serviceName: {{ $serviceName }}
55+
servicePort: {{ $servicePort }}
56+
{{- end }}
57+
{{- end }}
58+
{{- else }}
59+
- http:
60+
paths:
61+
- backend:
62+
{{- if $ingressApiIsStable }}
63+
service:
64+
name: {{ $serviceName }}
65+
port:
66+
number: {{ $servicePort }}
67+
{{- else }}
68+
serviceName: {{ $serviceName }}
69+
servicePort: {{ $servicePort }}
70+
{{- end }}
71+
{{- if $ingressPath }}
72+
path: {{ $ingressPath }}
73+
{{- end }}
74+
{{- if $ingressSupportsPathType }}
75+
pathType: {{ $ingressPathType }}
76+
{{- end }}
77+
{{- end -}}
78+
{{- end }}

charts/maildev/values.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,44 @@ securityContext: {}
7676
service:
7777
type: ClusterIP
7878

79+
ingress:
80+
enabled: false
81+
# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName
82+
# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress
83+
# ingressClassName: nginx
84+
# Values can be templated
85+
annotations: {}
86+
# kubernetes.io/ingress.class: nginx
87+
# kubernetes.io/tls-acme: "true"
88+
labels: {}
89+
path: /
90+
91+
# pathType is only for k8s >= 1.18
92+
pathType: Prefix
93+
94+
hosts:
95+
- chart-example.local
96+
## Extra paths to prepend to every host configuration. This is useful when working with annotation based services.
97+
extraPaths: []
98+
# - path: /*
99+
# backend:
100+
# serviceName: ssl-redirect
101+
# servicePort: use-annotation
102+
## Or for k8s > 1.19
103+
# - path: /*
104+
# pathType: Prefix
105+
# backend:
106+
# service:
107+
# name: ssl-redirect
108+
# port:
109+
# name: service
110+
111+
112+
tls: []
113+
# - secretName: chart-example-tls
114+
# hosts:
115+
# - chart-example.local
116+
79117
resources: {}
80118
# We usually recommend not to specify default resources and to leave this as a conscious
81119
# choice for the user. This also increases chances charts run on environments with little

0 commit comments

Comments
 (0)