Skip to content

Commit d0050df

Browse files
authored
feat: redirect chart support httproute (#165)
* feat: update chart version to 1.0.0 and add HTTPRoute template for redirects * fix route newline
1 parent fd7432c commit d0050df

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

charts/redirect/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.2.0
18+
version: 1.0.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- $root := . }}
2+
{{- if $root.Values.globalConfigs.routeEnabled }}
3+
{{- range .Values.websites }}
4+
---
5+
apiVersion: gateway.networking.k8s.io/v1
6+
kind: HTTPRoute
7+
metadata:
8+
name: {{ include "redirect.fullname" $root }}-{{ .name }}
9+
labels:
10+
{{- with $root.Values.globalConfigs.routeCommonLabels }}
11+
{{- toYaml . | nindent 4 }}
12+
{{- end}}
13+
{{- include "redirect.labels" $root | nindent 4 }}
14+
{{- with $root.Values.globalConfigs.routeCommonAnnotations }}
15+
annotations:
16+
{{- toYaml . | nindent 4 }}
17+
{{- end }}
18+
spec:
19+
{{- with $root.Values.globalConfigs.routeParentRefs }}
20+
parentRefs:
21+
{{- toYaml . | nindent 4 }}
22+
{{- end }}
23+
hostnames:
24+
- {{ .source | quote }}
25+
rules:
26+
- filters:
27+
- type: RequestRedirect
28+
requestRedirect:
29+
scheme: {{ .scheme | default "https" }}
30+
statusCode: {{ .statusCode | default 301 }}
31+
hostname: {{ .destination | quote }}
32+
{{- if not .include_path }}
33+
path:
34+
type: ReplaceFullPath
35+
replaceFullPath: {{ .path | default "/" | quote }}
36+
{{- end }}
37+
{{- end }}
38+
{{- end }}

charts/redirect/templates/ingress.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
{{- $root := . -}}
2+
{{- if $root.Values.globalConfigs.ingressEnabled }}
13
{{- range .Values.websites }}
4+
{{- $fullDestination := .destination }}
5+
{{- $scheme := .scheme | default "https" }}
6+
{{- $path := .path | default "" }}
7+
{{- $fullDestination = printf "%s://%s%s" $scheme .destination $path }}
28
---
39
apiVersion: networking.k8s.io/v1
410
kind: Ingress
@@ -14,10 +20,10 @@ metadata:
1420
{{- toYaml . | nindent 4 }}
1521
{{- end }}
1622
{{- if .include_path }}
17-
nginx.ingress.kubernetes.io/rewrite-target: {{ .destination }}/$1
23+
nginx.ingress.kubernetes.io/rewrite-target: {{ $fullDestination }}/$1
1824
{{- else }}
1925
nginx.ingress.kubernetes.io/configuration-snippet: |
20-
return 302 {{ .destination }};
26+
return 302 {{ $fullDestination }};
2127
{{- end }}
2228
spec:
2329
ingressClassName: {{ $.Values.globalConfigs.ingressClassName }}
@@ -42,3 +48,4 @@ spec:
4248
secretName: redirect-{{ .source }}-tls-cert
4349

4450
{{- end }}
51+
{{- end }}

charts/redirect/values.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ nameOverride: ""
66
fullnameOverride: ""
77

88
globalConfigs:
9+
ingressEnabled: true
910
ingressClassName: "nginx"
1011
ingressCommonLabels: {}
1112
ingressCommonAnnotations: {}
1213
# cert-manager.io/cluster-issuer: your-issuer
14+
routeEnabled: false
15+
routeCommonLabels: {}
16+
routeCommonAnnotations: {}
17+
routeParentRefs:
18+
- name: your-gateway
19+
namespace: your-gateway-namespace
1320

1421
websites:
1522
- name: test
1623
source: foo.example.com
17-
destination: https://bar.example.com
24+
destination: bar.example.com
25+
scheme: https
26+
statusCode: 301
27+
path: /test
1828
# if include_path is enabled , redirect with path in original url
1929
# foo.example.com/123 will be redirect to https://bar.example.com/123
2030
# - name: test

0 commit comments

Comments
 (0)