Skip to content

Commit c62b1f3

Browse files
committed
✨(helm) create ingress-redirects template
Create a new Helm template for ingress redirects and update the values.yaml file accordingly. We will be able to manage ingress redirects through Helm charts easily.
1 parent 150f5e0 commit c62b1f3

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{- if and .Values.ingress.enabled .Values.ingressRedirects.enabled }}
2+
{{- $fullName := include "impress.fullname" . -}}
3+
{{- $ns := .Release.Namespace -}}
4+
{{- $class := .Values.ingress.className -}}
5+
{{- $defaultHost := .Values.ingressRedirects.defaultHost | default .Values.ingress.host -}}
6+
7+
{{- range $i, $r := .Values.ingressRedirects.rules }}
8+
{{- $host := $r.host | default $defaultHost -}}
9+
{{- $from := $r.from | default "/home" -}}
10+
{{- $to := required (printf "ingressRedirects.rules[%d].to is required" $i) $r.to -}}
11+
{{- $name := printf "%s-redirect-%s" $fullName (replace "/" "-" (trimAll "/" $from)) | trunc 63 | trimSuffix "-" -}}
12+
13+
apiVersion: networking.k8s.io/v1
14+
kind: Ingress
15+
metadata:
16+
name: {{ $name }}
17+
namespace: {{ $ns }}
18+
annotations:
19+
{{- if or (not $r.code) (eq (toString $r.code) "301") }}
20+
nginx.ingress.kubernetes.io/permanent-redirect: "{{ $to }}"
21+
{{- else }}
22+
nginx.ingress.kubernetes.io/configuration-snippet: |
23+
return {{ $r.code }} {{ $to }};
24+
{{- end }}
25+
spec:
26+
{{- if $class }}
27+
ingressClassName: {{ $class }}
28+
{{- end }}
29+
rules:
30+
- host: {{ $host }}
31+
http:
32+
paths:
33+
- path: {{ $from }}
34+
pathType: Exact
35+
backend:
36+
service:
37+
name: {{ include "impress.frontend.fullname" $ }}
38+
port:
39+
number: {{ $.Values.frontend.service.port }}
40+
- path: {{ printf "%s/" (trimSuffix "/" $from) }}
41+
pathType: Exact
42+
backend:
43+
service:
44+
name: {{ include "impress.frontend.fullname" $ }}
45+
port:
46+
number: {{ $.Values.frontend.service.port }}
47+
---
48+
{{- end }}
49+
{{- end }}

src/helm/impress/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ ingressCollaborationWS:
8585
nginx.ingress.kubernetes.io/proxy-send-timeout: "86400"
8686
nginx.ingress.kubernetes.io/upstream-hash-by: $arg_room
8787

88+
ingressRedirects:
89+
enabled: false
90+
namePrefix: impress-redir
91+
defaultHost: impress.example.com
92+
rules: []
93+
8894
## @param ingressCollaborationApi.enabled whether to enable the Ingress or not
8995
## @param ingressCollaborationApi.className IngressClass to use for the Ingress
9096
## @param ingressCollaborationApi.host Host for the Ingress

0 commit comments

Comments
 (0)