Skip to content

Commit

Permalink
allow to define redirect domains
Browse files Browse the repository at this point in the history
Define a list of Domains that redirect to the domain of the project. The
idea is to provide the ability to redirect eg. www.domain.tld to
domain.tld
  • Loading branch information
ulfgebhardt committed Dec 5, 2024
1 parent 9e68997 commit 34a7967
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions deployment/helm/charts/ocelot-social/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
---
{{- define "joinRedirectMiddlewares" -}}
{{- $local := dict "first" true -}}
{{- range $k, $v := .Values.redirect_domains -}}{{- if not $local.first -}},{{- end -}}{{$.Release.Namespace}}-redirect-{{- $v | replace "." "-" -}}@kubernetescrd{{- $_ := set $local "first" false -}}{{- end -}}
{{- end -}}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Name }}
annotations:
traefik.ingress.kubernetes.io/router.middlewares: {{ include "joinRedirectMiddlewares" $ }}
cert-manager.io/issuer: {{ .Values.cert_manager.issuer | default (printf "%s-letsencrypt-staging" .Release.Name) }}
spec:
tls:
- hosts:
- {{ quote .Values.domain }}
{{- range .Values.redirect_domains }}
- {{ quote . }}
{{- end }}
secretName: {{ .Release.Name }}-letsencrypt-tls

rules:
Expand All @@ -28,3 +37,29 @@ spec:
port:
number: 3000
{{- end }}
{{- range .Values.redirect_domains }}
- host: {{ quote . }} # the service must be defined, else the redirect is not working
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: {{ $.Release.Name }}-maintenance
port:
number: 80
{{- end }}

{{- range .Values.redirect_domains }}
---
# Redirect with domain replacement
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: redirect-{{ . | replace "." "-" }}
spec:
redirectRegex:
regex: ^https://{{ . }}(.*)
replacement: https://{{ $.Values.domain }}${1}
permanent: true
{{- end }}
1 change: 1 addition & 0 deletions deployment/helm/charts/ocelot-social/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
domain: stage.ocelot.social
redirect_domains: []

cert_manager:
issuer:
Expand Down

0 comments on commit 34a7967

Please sign in to comment.