Merge pull request 'feat(helm): redirect plain HTTP to HTTPS on the ingresses' (#154) from feat/helm-https-redirect into main
This commit is contained in:
commit
a2c29998c5
4 files changed
+63
-4
No files matched your search
@@ -170,3 +170,53 @@ $secret being the chart secret to read values from.
|
||||
medium: Memory
|
||||
sizeLimit: 64Mi
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
HTTPS redirect of an ingress: include with (dict "root" . "ingress" <values>
|
||||
"name" <ingress name>). Traefik needs a redirectScheme middleware, other
|
||||
controllers an annotation. */}}
|
||||
{{- define "uptimesebi.redirects" -}}
|
||||
{{- $i := .ingress -}}
|
||||
{{- if and $i.tls.enabled $i.tls.redirect }}true{{ end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "uptimesebi.traefik" -}}
|
||||
{{- $i := .ingress -}}
|
||||
{{- if contains "traefik" ($i.className | default "") -}}true
|
||||
{{- else if and (not $i.className) (.root.Capabilities.APIVersions.Has "traefik.io/v1alpha1/Middleware") -}}true
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* the ingress's annotations, with those the redirect needs. */}}
|
||||
{{- define "uptimesebi.ingressAnnotations" -}}
|
||||
{{- $a := deepCopy (.ingress.annotations | default dict) -}}
|
||||
{{- if include "uptimesebi.redirects" . -}}
|
||||
{{- if include "uptimesebi.traefik" . -}}
|
||||
{{- $key := "traefik.ingress.kubernetes.io/router.middlewares" -}}
|
||||
{{- $mw := printf "%s-%s-https@kubernetescrd" .root.Release.Namespace .name -}}
|
||||
{{- with get $a $key }}{{ $mw = printf "%s,%s" $mw . }}{{ end -}}
|
||||
{{- $_ := set $a $key $mw -}}
|
||||
{{- else -}}
|
||||
{{- $_ := set $a "nginx.ingress.kubernetes.io/ssl-redirect" "true" -}}
|
||||
{{- $_ := set $a "haproxy.org/ssl-redirect" "true" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- with $a }}{{ toYaml . }}{{ end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* the Traefik middleware the redirect uses, if it needs one. */}}
|
||||
{{- define "uptimesebi.redirectMiddleware" -}}
|
||||
{{- if and (include "uptimesebi.redirects" .) (include "uptimesebi.traefik" .) }}
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1
|
||||
kind: Middleware
|
||||
metadata:
|
||||
name: {{ .name }}-https
|
||||
labels:
|
||||
{{- include "uptimesebi.labels" .root | nindent 4 }}
|
||||
spec:
|
||||
redirectScheme:
|
||||
scheme: https
|
||||
permanent: true
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
@@ -1,13 +1,14 @@
|
||||
{{- if .Values.ingress.enabled }}
|
||||
{{- $ing := dict "root" . "ingress" .Values.ingress "name" (include "uptimesebi.fullname" .) }}
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ include "uptimesebi.fullname" . }}
|
||||
labels:
|
||||
{{- include "uptimesebi.labels" . | nindent 4 }}
|
||||
{{- with .Values.ingress.annotations }}
|
||||
{{- with include "uptimesebi.ingressAnnotations" $ing }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with .Values.ingress.className }}
|
||||
@@ -29,4 +30,5 @@ spec:
|
||||
name: {{ include "uptimesebi.fullname" . }}-api
|
||||
port:
|
||||
name: http
|
||||
{{- include "uptimesebi.redirectMiddleware" $ing }}
|
||||
{{- end }}
|
||||
@@ -118,6 +118,7 @@ spec:
|
||||
{{- include "uptimesebi.selector" (list . "statuspage") | nindent 6 }}
|
||||
{{- end }}
|
||||
{{- if .Values.statuspage.ingress.enabled }}
|
||||
{{- $ing := dict "root" . "ingress" .Values.statuspage.ingress "name" $name }}
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
@@ -125,9 +126,9 @@ metadata:
|
||||
name: {{ $name }}
|
||||
labels:
|
||||
{{- include "uptimesebi.labels" . | nindent 4 }}
|
||||
{{- with .Values.statuspage.ingress.annotations }}
|
||||
{{- with include "uptimesebi.ingressAnnotations" $ing }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with .Values.statuspage.ingress.className }}
|
||||
@@ -152,5 +153,6 @@ spec:
|
||||
port:
|
||||
name: http
|
||||
{{- end }}
|
||||
{{- include "uptimesebi.redirectMiddleware" $ing }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -144,6 +144,9 @@ ingress:
|
||||
enabled: false
|
||||
# Secret with the certificate, e.g. made by cert-manager.
|
||||
secretName: ""
|
||||
# Send plain HTTP to HTTPS: through a redirectScheme middleware with
|
||||
# Traefik, by annotation with ingress-nginx and HAProxy.
|
||||
redirect: true
|
||||
|
||||
# -- Checker --
|
||||
# A checker in the cluster, for checks from the cluster's region. Create
|
||||
@@ -197,6 +200,8 @@ statuspage:
|
||||
tls:
|
||||
enabled: false
|
||||
secretName: ""
|
||||
# Send plain HTTP to HTTPS, as for the console.
|
||||
redirect: true
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
|
||||
Reference in new issue
Block a user