From 4b57df1d86d16230f3482364b3213ca075545bf3 Mon Sep 17 00:00:00 2001 From: Julio Arias Date: Thu, 6 Jan 2022 14:55:33 -0600 Subject: [PATCH] bugfix: Fix helm chart ingress template This changes fixes the ingress spec to match the API version either v1 or v1beta1, previously the apiVersion was change according to the K8S version but no further changes where made to actually match the new v1 API spec. This cause issues deploying to clusters with versions 1.19+ Signed-off-by: Julio Arias --- contrib/chart/backstage/Chart.yaml | 2 +- .../chart/backstage/templates/ingress.yaml | 71 ++++++++++++++++--- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/contrib/chart/backstage/Chart.yaml b/contrib/chart/backstage/Chart.yaml index 9154368475..21f7084415 100644 --- a/contrib/chart/backstage/Chart.yaml +++ b/contrib/chart/backstage/Chart.yaml @@ -5,7 +5,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. -version: 0.1.2 +version: 0.1.3 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. diff --git a/contrib/chart/backstage/templates/ingress.yaml b/contrib/chart/backstage/templates/ingress.yaml index 3ec4990561..3fa052485e 100644 --- a/contrib/chart/backstage/templates/ingress.yaml +++ b/contrib/chart/backstage/templates/ingress.yaml @@ -3,10 +3,10 @@ {{- $lighthouseUrl := urlParse .Values.appConfig.lighthouse.baseUrl}} {{/* Determine the api type for the ingress */}} -{{- if lt .Capabilities.KubeVersion.Minor "19" }} -apiVersion: networking.k8s.io/v1beta1 -{{- else if ge .Capabilities.KubeVersion.Minor "19" }} +{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} apiVersion: networking.k8s.io/v1 +{{- else -}} +apiVersion: networking.k8s.io/v1beta1 {{- end }} kind: Ingress metadata: @@ -29,31 +29,60 @@ spec: - {{ $frontendUrl.host }} - {{ $backendUrl.host }} - {{ $lighthouseUrl.host }} - rules: - host: {{ $frontendUrl.host }} http: paths: - path: / + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + pathType: Prefix + {{- end }} backend: + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + service: + name: {{ include "frontend.serviceName" . }} + port: + number: 80 + {{- else -}} serviceName: {{ include "frontend.serviceName" . }} servicePort: 80 - {{/* Route the backend inside the same hostname as the frontend when they are the same */}} - {{- if eq $frontendUrl.host $backendUrl.host}} + {{- end }} + {{/* Route the backend inside the same hostname as the frontend when they are the same */}} + {{- if eq $frontendUrl.host $backendUrl.host}} - path: /api/ + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + pathType: Prefix + {{- end }} backend: + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + service: + name: {{ include "backend.serviceName" . }} + port: + number: 80 + {{- else -}} serviceName: {{ include "backend.serviceName" . }} servicePort: 80 - {{/* Route the backend through a different host */}} - {{- else -}} + {{- end }} + {{/* Route the backend through a different host */}} + {{- else -}} - host: {{ $backendUrl.host }} http: paths: - path: {{ $backendUrl.path | default "/" }} + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + pathType: Prefix + {{- end }} backend: + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + service: + name: {{ include "frontend.serviceName" . }} + port: + number: 80 + {{- else -}} serviceName: {{ include "backend.serviceName" . }} servicePort: 80 - {{- end }} + {{- end }} + {{- end }} {{/* Route lighthouse through a different host */}} {{- if not ( eq $frontendUrl.host $lighthouseUrl.host ) }} @@ -61,13 +90,27 @@ spec: http: paths: - path: {{ $lighthouseUrl.path | default "/" }} + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + pathType: Prefix + {{- end }} backend: + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + service: + name: {{ include "lighthouse.serviceName" . }} + port: + number: 80 + {{- else -}} serviceName: {{ include "lighthouse.serviceName" . }} servicePort: 80 + {{- end }} {{- else }} {{/* Route lighthouse by path with re-write rules when it is hosted under the same hostname */}} --- +{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} +apiVersion: networking.k8s.io/v1 +{{- else -}} apiVersion: networking.k8s.io/v1beta1 +{{- end }} kind: Ingress metadata: name: {{ include "backstage.fullname" . }}-ingress-lighthouse @@ -92,7 +135,17 @@ spec: http: paths: - path: {{$lighthouseUrl.path}}(/|$)(.*) + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + pathType: Prefix + {{- end }} backend: + {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }} + service: + name: {{ include "lighthouse.serviceName" . }} + port: + number: 80 + {{- else -}} serviceName: {{ include "lighthouse.serviceName" . }} servicePort: 80 + {{- end }} {{- end }}