Skip to content

Commit

Permalink
feat: middleware inside proper namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Crty committed Nov 6, 2024
1 parent e056294 commit adcf0f6
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 7 deletions.
2 changes: 1 addition & 1 deletion helm-charts/generic-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: generic-app
description: A Helm Chart for Generic App
type: application
version: 0.3.10
version: 0.3.11
2 changes: 1 addition & 1 deletion helm-charts/generic-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Create the name of the service account to use
{{- $fullName := include "generic-app.fullname" . -}}
{{- $middlewares := "" -}}
{{- range .Values.ingress.redirections }}
{{- $middlewareName := printf "traefik-%s-redirect-to-%s@kubernetescrd" $fullName (include "toSlug" .to) -}}
{{- $middlewareName := printf "%s-%s-redirect-to-%s@kubernetescrd" $.Release.Namespace $fullName (include "toSlug" .to) -}}
{{- if $middlewares }}
{{- $middlewares = printf "%s,%s" $middlewares $middlewareName -}}
{{- else }}
Expand Down
2 changes: 1 addition & 1 deletion helm-charts/generic-app/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
template:
spec:
containers:
- image: {{ include "generic-app.image" $.Values | quote }}
- image: {{ if $cronjob.image }}{{ include "generic-app.image" $cronjob | quote }}{{ else }}{{ include "generic-app.image" $.Values | quote }}{{ end }}
name: {{ $fullName }}-{{ $name }}
imagePullPolicy: Always
command:
Expand Down
1 change: 0 additions & 1 deletion helm-charts/generic-app/templates/middleware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ $fullName }}-redirect-to-{{ .to | include "toSlug" }}
namespace: traefik
labels:
{{- include "generic-app.labels" $ | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ should create middleware redirections:
metadata:
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
traefik.ingress.kubernetes.io/router.middlewares: traefik-test-generic-app-redirect-to-crty-dev@kubernetescrd,traefik-redirect-to-https@kubernetescrd
traefik.ingress.kubernetes.io/router.middlewares: NAMESPACE-test-generic-app-redirect-to-crty-dev@kubernetescrd,traefik-redirect-to-https@kubernetescrd
name: test-generic-app
spec:
ingressClassName: traefik
Expand Down Expand Up @@ -67,7 +67,6 @@ should create middleware redirections:
app.kubernetes.io/name: generic-app
helm.sh/chart: generic-app-0.1.0
name: test-generic-app-redirect-to-crty-dev
namespace: traefik
spec:
redirectRegex:
permanent: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
should have a redirect middleware:
1: |
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
traefik.ingress.kubernetes.io/router.middlewares: NAMESPACE-test-generic-app-redirect-to-crty-dev@kubernetescrd,traefik-redirect-to-https@kubernetescrd
name: test-generic-app
spec:
ingressClassName: traefik
rules:
- host: crty.dev
http:
paths:
- backend:
service:
name: test-generic-app
port:
number: 80
path: /
pathType: Prefix
- host: www.crty.dev
http:
paths:
- backend:
service:
name: test-generic-app
port:
number: 80
path: /
pathType: Prefix
- host: infra.crty.dev
http:
paths:
- backend:
service:
name: test-generic-app
port:
number: 80
path: /
pathType: Prefix
tls:
- hosts:
- crty.dev
- www.crty.dev
- infra.crty.dev
secretName: test-generic-app-cert
2: |
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
labels:
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: generic-app
helm.sh/chart: generic-app-0.1.0
name: test-generic-app-redirect-to-crty-dev
spec:
redirectRegex:
permanent: true
regex: ^https?://(www\.crty\.dev|infra\.crty\.dev)(/.*)
replacement: https://crty.dev$2
16 changes: 15 additions & 1 deletion helm-charts/generic-app/tests/cronjob_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ tests:
- "hello world"
schedule: "* * * * *"
asserts:
- matchSnapshot: {}
- matchSnapshot: {}
- it: should have a cronjob with custom image
set:
cronJobs:
cron-1:
image: "busybox"
tag: "19"
command:
- echo
- "hello world"
schedule: "* * * * *"
asserts:
- equal:
path: spec.jobTemplate.spec.template.spec.containers[0].image
value: busybox:19
26 changes: 26 additions & 0 deletions helm-charts/generic-app/tests/middleware_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json

suite: test cronjob
release:
name: test
chart:
version: 0.1.0
templates:
- middleware.yaml
- ingress.yaml
tests:
- it: should have a redirect middleware
set:
ingress:
enabled: true
hosts:
- crty.dev
- www.crty.dev
- infra.crty.dev
redirections:
- from:
- www.crty.dev
- infra.crty.dev
to: crty.dev
asserts:
- matchSnapshot: {}

0 comments on commit adcf0f6

Please sign in to comment.