From e97710cb078dd9802a2bfbe05297c4e2b02997f0 Mon Sep 17 00:00:00 2001 From: Simon KP <“simon@techops.services”> Date: Thu, 29 Feb 2024 13:22:32 +1100 Subject: [PATCH] common: ability to specify multiple Ingress hosts --- charts/common/Chart.yaml | 2 +- charts/common/templates/NOTES.txt | 4 +--- charts/common/templates/ingress.yaml | 10 +++++++--- charts/common/templates/middleware-httpBasicAuth.yaml | 2 +- .../common/templates/middleware-httpWwwRedirect.yaml | 4 ++-- charts/common/test-values.yaml | 11 ++++------- charts/common/values.yaml | 9 +++------ 7 files changed, 19 insertions(+), 23 deletions(-) diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 406a29a..cc64b83 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -15,7 +15,7 @@ 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: 0.0.28 +version: 0.0.29 # 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 diff --git a/charts/common/templates/NOTES.txt b/charts/common/templates/NOTES.txt index db972d9..5e541dc 100644 --- a/charts/common/templates/NOTES.txt +++ b/charts/common/templates/NOTES.txt @@ -1,9 +1,7 @@ 1. Get the application URL by running these commands: {{- if .Values.ingress.enabled }} {{- range $host := .Values.ingress.hosts }} - {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} - {{- end }} + http{{ if $.Values.service.tls }}s{{ end }}://{{ $host }} {{- end }} {{- else if and .Values.service.enabled (contains "NodePort" .Values.service.type) }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.fullname" . }}) diff --git a/charts/common/templates/ingress.yaml b/charts/common/templates/ingress.yaml index 26be075..74e6b61 100644 --- a/charts/common/templates/ingress.yaml +++ b/charts/common/templates/ingress.yaml @@ -16,18 +16,21 @@ metadata: {{- $middlewares = append $middlewares (printf "%s-%s-http-www-redirect@kubernetescrd" .Release.Namespace $fullName) }} {{- end }} {{- if ne (len $middlewares) 0 }} - traefik.ingress.kubernetes.io/router.middlewares: {{ join "," $middlewares }} + traefik.ingress.kubernetes.io/router.middlewares: {{ join ", " $middlewares }} {{- end }} spec: ingressClassName: {{ .Values.ingressClassName }} {{- if .Values.service.tls.enabled }} tls: - hosts: - - {{ .Values.ingress.host }} + {{- range .Values.ingress.hosts }} + - {{ . | quote }} + {{- end }} secretName: {{ $fullName }}-tls {{- end }} rules: - - host: {{ .Values.ingress.host }} + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} http: paths: - backend: @@ -37,4 +40,5 @@ spec: name: http path: / pathType: ImplementationSpecific + {{- end }} {{- end }} diff --git a/charts/common/templates/middleware-httpBasicAuth.yaml b/charts/common/templates/middleware-httpBasicAuth.yaml index 6845d1b..9763dd1 100644 --- a/charts/common/templates/middleware-httpBasicAuth.yaml +++ b/charts/common/templates/middleware-httpBasicAuth.yaml @@ -11,7 +11,7 @@ stringData: {{ $item }} {{- end }} --- -apiVersion: traefik.io/v1alpha1 +apiVersion: traefik.containo.us/v1alpha1 kind: Middleware metadata: name: {{ $fullName }}-http-basic-auth diff --git a/charts/common/templates/middleware-httpWwwRedirect.yaml b/charts/common/templates/middleware-httpWwwRedirect.yaml index 9555792..c228aa5 100644 --- a/charts/common/templates/middleware-httpWwwRedirect.yaml +++ b/charts/common/templates/middleware-httpWwwRedirect.yaml @@ -1,7 +1,7 @@ {{- if .Values.httpWwwRedirect.enabled }} {{- $fullName := include "common.fullname" . -}} --- -apiVersion: traefik.io/v1alpha1 +apiVersion: traefik.containo.us/v1alpha1 kind: Middleware metadata: name: {{ $fullName }}-http-www-redirect @@ -9,5 +9,5 @@ spec: redirectRegex: permanent: true regex: "^(http)://(www\\.)?(.*)" - replacement: "https://$$3" + replacement: "https://$3" {{- end }} diff --git a/charts/common/test-values.yaml b/charts/common/test-values.yaml index 117e3cd..805621c 100644 --- a/charts/common/test-values.yaml +++ b/charts/common/test-values.yaml @@ -9,7 +9,7 @@ service: type: ClusterIP containerPort: 5000 tls: - enabled: false + enabled: true issuerName: "test" deployment: @@ -186,12 +186,9 @@ ingress: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" - host: example.com - - tls: - - secretName: chart-example-tls - hosts: - - chart-example.local + hosts: + - example.com + - www.example.com resources: limits: diff --git a/charts/common/values.yaml b/charts/common/values.yaml index 333e1cd..ae35eea 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -197,12 +197,9 @@ ingress: {} # {} # # kubernetes.io/ingress.class: nginx # # kubernetes.io/tls-acme: "true" -# host: example.com -# -# tls: [] -# # - secretName: chart-example-tls -# # hosts: -# # - chart-example.local +# hosts: +# - example.com +# - www.example.com # If enabled will create Traefik Middleware and apply to Ingress # to redirect http to https and www to non-www