From 668a256de1827952135dc09aee810c3558e8609b Mon Sep 17 00:00:00 2001 From: Glenn de Haan Date: Fri, 18 Nov 2022 11:15:15 +0100 Subject: [PATCH] Added the traefik-redirect chart --- charts/traefik-redirect/.helmignore | 23 +++++++ charts/traefik-redirect/Chart.yaml | 34 ++++++++++ .../traefik-redirect/templates/_helpers.tpl | 62 +++++++++++++++++++ .../traefik-redirect/templates/ingress.yaml | 23 +++++++ .../templates/middleware.yaml | 11 ++++ charts/traefik-redirect/values.yaml | 15 +++++ 6 files changed, 168 insertions(+) create mode 100644 charts/traefik-redirect/.helmignore create mode 100644 charts/traefik-redirect/Chart.yaml create mode 100644 charts/traefik-redirect/templates/_helpers.tpl create mode 100644 charts/traefik-redirect/templates/ingress.yaml create mode 100644 charts/traefik-redirect/templates/middleware.yaml create mode 100644 charts/traefik-redirect/values.yaml diff --git a/charts/traefik-redirect/.helmignore b/charts/traefik-redirect/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/traefik-redirect/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/traefik-redirect/Chart.yaml b/charts/traefik-redirect/Chart.yaml new file mode 100644 index 0000000..5c0db8a --- /dev/null +++ b/charts/traefik-redirect/Chart.yaml @@ -0,0 +1,34 @@ +apiVersion: v2 +name: traefik-redirect +description: A Helm chart to create a simple http(s) redirect within Traefik +home: https://github.com/glenndehaan/charts +keywords: + - kubernetes + - traefik + - redirect +maintainers: + - email: glenn@dehaan.cloud + name: glenndehaan +sources: + - https://github.com/glenndehaan/charts + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 1.0.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/charts/traefik-redirect/templates/_helpers.tpl b/charts/traefik-redirect/templates/_helpers.tpl new file mode 100644 index 0000000..3687a24 --- /dev/null +++ b/charts/traefik-redirect/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "traefik-redirect.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "traefik-redirect.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "traefik-redirect.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "traefik-redirect.labels" -}} +helm.sh/chart: {{ include "traefik-redirect.chart" . }} +{{ include "traefik-redirect.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "traefik-redirect.selectorLabels" -}} +app.kubernetes.io/name: {{ include "traefik-redirect.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "traefik-redirect.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "traefik-redirect.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/traefik-redirect/templates/ingress.yaml b/charts/traefik-redirect/templates/ingress.yaml new file mode 100644 index 0000000..e4252e9 --- /dev/null +++ b/charts/traefik-redirect/templates/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: traefik.containo.us/v1alpha1 +kind: IngressRoute +metadata: + name: {{ include "traefik-redirect.fullname" . }} + labels: + {{- include "traefik-redirect.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.entryPoints }} + entryPoints: + {{- toYaml . | nindent 4 }} + {{- end }} + routes: + - match: 'Host(`{{ .Values.ingress.host }}`) && PathPrefix(`/`)' + kind: Rule + middlewares: + - name: {{ include "traefik-redirect.fullname" . }} + services: + - name: noop@internal + kind: TraefikService diff --git a/charts/traefik-redirect/templates/middleware.yaml b/charts/traefik-redirect/templates/middleware.yaml new file mode 100644 index 0000000..e93a5ed --- /dev/null +++ b/charts/traefik-redirect/templates/middleware.yaml @@ -0,0 +1,11 @@ +apiVersion: traefik.containo.us/v1alpha1 +kind: Middleware +metadata: + name: {{ include "traefik-redirect.fullname" . }} + labels: + {{- include "traefik-redirect.labels" . | nindent 4 }} +spec: + redirectRegex: + regex: ^https?://{{ .Values.ingress.host }}/(.*) + replacement: https://{{ .Values.ingress.redirect }}/${1} + permanent: true diff --git a/charts/traefik-redirect/values.yaml b/charts/traefik-redirect/values.yaml new file mode 100644 index 0000000..93f5fb9 --- /dev/null +++ b/charts/traefik-redirect/values.yaml @@ -0,0 +1,15 @@ +# Default values for traefik-redirect. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +nameOverride: "" +fullnameOverride: "" + +ingress: + entryPoints: + - websecure + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + host: chart-example.local + redirect: chart-example-new.local