From 7d662fcacdb9a6313cc4f94e76086e5c66c99b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20J=C3=A1ky?= Date: Mon, 23 Jan 2023 15:48:14 +0100 Subject: [PATCH] Updated Ingress chart template (#230) * feat: enhanced Ingress template K8s compatibility * feat: bumped chart version 0.2.1->0.3.0 --- charts/telescopes/Chart.yaml | 4 +- charts/telescopes/templates/deployment.yaml | 10 +++- charts/telescopes/templates/ingress.yaml | 62 ++++++++++++++------- charts/telescopes/values.yaml | 38 ++++++++----- 4 files changed, 76 insertions(+), 38 deletions(-) diff --git a/charts/telescopes/Chart.yaml b/charts/telescopes/Chart.yaml index 2ca71c89..974e3d4a 100755 --- a/charts/telescopes/Chart.yaml +++ b/charts/telescopes/Chart.yaml @@ -3,7 +3,7 @@ name: telescopes home: https://banzaicloud.com sources: - https://github.com/banzaicloud/banzai-charts -version: 0.2.1 +version: 0.3.0 appVersion: 0.5.3 description: A Telescopes Helm chart for Kubernetes keywords: @@ -25,4 +25,4 @@ icon: https://banzaicloud.com/img/banzai-cloud-logo.svg # 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 \ No newline at end of file +# type: application diff --git a/charts/telescopes/templates/deployment.yaml b/charts/telescopes/templates/deployment.yaml index 98e13b1f..bf919999 100644 --- a/charts/telescopes/templates/deployment.yaml +++ b/charts/telescopes/templates/deployment.yaml @@ -1,5 +1,9 @@ -{{- $url := splitList "/" (index .Values.ingress.hosts 0) }} -{{- $basePath := (rest $url | join "/") }} +{{- $basePath := "" -}} +{{- with (first .Values.ingress.hosts )}} + {{- with (first .paths) }} + {{- $basePath = .path }} + {{- end }} +{{- end }} apiVersion: apps/v1 kind: Deployment metadata: @@ -39,7 +43,7 @@ spec: env: {{- if .Values.ingress.hosts }} - name: TELESCOPES_BASEPATH - value: /{{ $basePath }} + value: {{ $basePath }} {{- end }} command: - "/bin/sh" diff --git a/charts/telescopes/templates/ingress.yaml b/charts/telescopes/templates/ingress.yaml index 89288e85..6c29a399 100644 --- a/charts/telescopes/templates/ingress.yaml +++ b/charts/telescopes/templates/ingress.yaml @@ -1,43 +1,65 @@ {{- if .Values.ingress.enabled -}} -{{- $serviceName := include "telescopes.fullname" . -}} -{{- $servicePort := .Values.service.internalPort -}} -{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +{{- $fullName := include "telescopes.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1beta1 {{- else -}} apiVersion: extensions/v1beta1 {{- end }} kind: Ingress metadata: - name: {{ template "telescopes.fullname" . }} + name: {{ $fullName }} labels: app: {{ template "telescopes.name" . }} chart: {{ .Chart.Name }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} -{{- with .Values.ingress.annotations }} + {{- with .Values.ingress.annotations }} annotations: -{{ toYaml . | indent 4 }} -{{- end }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: -{{- if .Values.ingress.tls }} + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} tls: - {{- range .Values.ingress.tls }} + {{- range .Values.ingress.tls }} - hosts: - {{- range .hosts }} - - {{ . }} - {{- end }} + {{- range .hosts }} + - {{ . | quote }} + {{- end }} secretName: {{ .secretName }} + {{- end }} {{- end }} -{{- end }} rules: - {{- range .Values.ingress.hosts }} - {{- $url := splitList "/" . }} - - host: {{ first $url }} + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} http: paths: - - path: /{{ rest $url | join "/" }} + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} backend: - serviceName: {{ $serviceName }} - servicePort: {{ $servicePort }} - {{- end}} + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} {{- end }} + diff --git a/charts/telescopes/values.yaml b/charts/telescopes/values.yaml index dd777dc5..242965e7 100644 --- a/charts/telescopes/values.yaml +++ b/charts/telescopes/values.yaml @@ -35,19 +35,31 @@ service: # annotations: ingress: - enabled: false - annotations: {} - #kubernetes.io/ingress.class: traefik - #ingress.kubernetes.io/ssl-redirect: "false" - #traefik.frontend.rule.type: PathPrefix - hosts: - - "/" - # - "domain.com/xyz" - # - "domain.com" - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local + # -- Enable [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/). + enabled: false + + # -- Ingress [class name](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class). + className: "" + + # -- Annotations to be added to the ingress. + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + + # -- Ingress host configuration. + # @default -- See [values.yaml](values.yaml). + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + + # -- Ingress TLS configuration. + # @default -- See [values.yaml](values.yaml). + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local podAnnotations: {} # prometheus.io/scrape: "true"