Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ingress support #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions charts/maildev/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ include "maildev.fullname" . }}'

{{- end }}
{{- if .Values.ingress.enabled }}

From outside the cluster, the server URL(s) are:
{{- range .Values.ingress.hosts }}
http://{{ . }}
{{- end }}
{{- end }}
38 changes: 38 additions & 0 deletions charts/maildev/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,41 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Get KubeVersion removing pre-release information.
*/}}
{{- define "maildev.kubeVersion" -}}
{{- default .Capabilities.KubeVersion.Version (regexFind "v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version) -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for ingress.
*/}}
{{- define "maildev.ingress.apiVersion" -}}
{{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19.x" (include "maildev.kubeVersion" .)) -}}
{{- print "networking.k8s.io/v1" -}}
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- else -}}
{{- print "extensions/v1beta1" -}}
{{- end -}}
{{- end -}}
{{/*
Return if ingress is stable.
*/}}
{{- define "maildev.ingress.isStable" -}}
{{- eq (include "maildev.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
{{- end -}}
{{/*
Return if ingress supports ingressClassName.
*/}}
{{- define "maildev.ingress.supportsIngressClassName" -}}
{{- or (eq (include "maildev.ingress.isStable" .) "true") (and (eq (include "maildev.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "maildev.kubeVersion" .))) -}}
{{- end -}}
{{/*
Return if ingress supports pathType.
*/}}
{{- define "maildev.ingress.supportsPathType" -}}
{{- or (eq (include "maildev.ingress.isStable" .) "true") (and (eq (include "maildev.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "maildev.kubeVersion" .))) -}}
{{- end -}}
77 changes: 77 additions & 0 deletions charts/maildev/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{{- if .Values.ingress.enabled -}}
{{- $ingressApiIsStable := eq (include "maildev.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "maildev.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "maildev.ingress.supportsPathType" .) "true" -}}
{{- $fullName := include "maildev.fullname" . -}}
{{- $servicePort := .Values.ports.web -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $ingressPathType := .Values.ingress.pathType -}}
{{- $extraPaths := .Values.ingress.extraPaths -}}
apiVersion: {{ include "maildev.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "maildev.labels" . | nindent 4 }}
{{- if .Values.ingress.labels }}
{{ toYaml .Values.ingress.labels | indent 4 }}
{{- end }}
{{- if .Values.ingress.annotations }}
annotations:
{{- range $key, $value := .Values.ingress.annotations }}
{{ $key }}: {{ tpl $value $ | quote }}
{{- end }}
{{- end }}
spec:
{{- if and $ingressSupportsIngressClassName .Values.ingress.ingressClassName }}
ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end -}}
{{- if .Values.ingress.tls }}
tls:
{{ tpl (toYaml .Values.ingress.tls) $ | indent 4 }}
{{- end }}
rules:
{{- if .Values.ingress.hosts }}
{{- range .Values.ingress.hosts }}
- host: {{ tpl . $}}
http:
paths:
{{- if $extraPaths }}
{{ toYaml $extraPaths | indent 10 }}
{{- end }}
- path: {{ $ingressPath }}
{{- if $ingressSupportsPathType }}
pathType: {{ $ingressPathType }}
{{- end }}
backend:
{{- if $ingressApiIsStable }}
service:
name: {{ $fullName }}
port:
number: {{ $servicePort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $servicePort }}
{{- end }}
{{- end }}
{{- else }}
- http:
paths:
- backend:
{{- if $ingressApiIsStable }}
service:
name: {{ $fullName }}
port:
number: {{ $servicePort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $servicePort }}
{{- end }}
{{- if $ingressPath }}
path: {{ $ingressPath }}
{{- end }}
{{- if $ingressSupportsPathType }}
pathType: {{ $ingressPathType }}
{{- end }}
{{- end -}}
{{- end }}
17 changes: 0 additions & 17 deletions charts/maildev/templates/service-web.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "maildev.fullname" . }}-smtp
name: {{ include "maildev.fullname" . }}
labels:
{{- include "maildev.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- name: smtp-{{ .Values.ports.smtp }}-tcp
- name: smtp
port: {{ .Values.ports.smtp }}
protocol: TCP
targetPort: {{ .Values.ports.smtp }}
- name: web
port: {{ .Values.ports.web }}
protocol: TCP
targetPort: {{ .Values.ports.web }}
selector:
{{- include "maildev.selectorLabels" . | nindent 4 }}
{{- end }}
38 changes: 38 additions & 0 deletions charts/maildev/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,44 @@ securityContext: {}
service:
type: ClusterIP

ingress:
enabled: false
# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName
# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress
# ingressClassName: nginx
# Values can be templated
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
labels: {}
path: /

# pathType is only for k8s >= 1.18
pathType: Prefix

hosts:
- chart-example.local
## Extra paths to prepend to every host configuration. This is useful when working with annotation based services.
extraPaths: []
# - path: /*
# backend:
# serviceName: ssl-redirect
# servicePort: use-annotation
## Or for k8s > 1.19
# - path: /*
# pathType: Prefix
# backend:
# service:
# name: ssl-redirect
# port:
# name: service


tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
Expand Down