From 256ac4604488f4ebcc677830ed567e3e9404f7a6 Mon Sep 17 00:00:00 2001 From: ace Date: Mon, 18 Jul 2022 16:41:12 +0300 Subject: [PATCH] roundcube: update ingress template --- roundcube/Chart.yaml | 2 +- roundcube/templates/_helpers.tpl | 20 +++++++++ roundcube/templates/ingress.yaml | 70 +++++++++++++++++++++----------- 3 files changed, 67 insertions(+), 25 deletions(-) diff --git a/roundcube/Chart.yaml b/roundcube/Chart.yaml index 02e6e9f..6fc8461 100644 --- a/roundcube/Chart.yaml +++ b/roundcube/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 appVersion: "1.4.13" description: A Helm chart for Kubernetes name: roundcube -version: 0.2.7 +version: 0.2.8 icon: https://github.com/roundcube/roundcubemail/blob/master/skins/classic/images/roundcube_logo.png diff --git a/roundcube/templates/_helpers.tpl b/roundcube/templates/_helpers.tpl index 59e2d43..5471f6a 100644 --- a/roundcube/templates/_helpers.tpl +++ b/roundcube/templates/_helpers.tpl @@ -30,3 +30,23 @@ Create chart name and version as used by the chart label. {{- define "roundcube.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} + +{{/* +Common labels +*/}} +{{- define "roundcube.labels" -}} +helm.sh/chart: {{ include "roundcube.chart" . }} +{{ include "roundcube.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "roundcube.selectorLabels" -}} +app.kubernetes.io/name: {{ include "roundcube.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/roundcube/templates/ingress.yaml b/roundcube/templates/ingress.yaml index f7ad946..98be2bf 100644 --- a/roundcube/templates/ingress.yaml +++ b/roundcube/templates/ingress.yaml @@ -1,39 +1,61 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "roundcube.fullname" . -}} -{{- $servicePort := .Values.service.port -}} -{{- $ingressPath := .Values.ingress.path -}} +{{- $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: {{ $fullName }} labels: - app: {{ template "roundcube.name" . }} - chart: {{ template "roundcube.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} -{{- with .Values.ingress.annotations }} + {{- include "roundcube.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} annotations: -{{ toYaml . | indent 4 }} -{{- end }} -spec: -{{- if .Values.ingress.tls }} - tls: - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . }} - {{- end }} - secretName: {{ .secretName }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- 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 }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} {{- end }} -{{- end }} rules: - {{- range .Values.ingress.hosts }} - - host: {{ . }} + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} http: paths: - - path: {{ $ingressPath }} + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} serviceName: {{ $fullName }} - servicePort: http - {{- end }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} {{- end }}