From 414ab02fd12ce9db022b75720e48686570da03ff Mon Sep 17 00:00:00 2001 From: Shyam Vyas Date: Wed, 24 Aug 2022 18:41:55 +0530 Subject: [PATCH] feat: update healthchecks helm chart by making templating related changes in ingress --- charts/healthchecks/Chart.lock | 6 ++-- charts/healthchecks/Chart.yaml | 8 ++--- charts/healthchecks/templates/_helpers.tpl | 37 ++++++++++++++++++++ charts/healthchecks/templates/ingress.yaml | 39 ++++++++++------------ 4 files changed, 61 insertions(+), 29 deletions(-) diff --git a/charts/healthchecks/Chart.lock b/charts/healthchecks/Chart.lock index 26bb568..5d32fa3 100644 --- a/charts/healthchecks/Chart.lock +++ b/charts/healthchecks/Chart.lock @@ -1,6 +1,6 @@ dependencies: - name: postgresql repository: https://charts.bitnami.com/bitnami - version: 9.1.1 -digest: sha256:4949a7dab1ae4d5ba4f6ecf12667c6b720d385d66d97f14af018e864da292cd7 -generated: "2021-05-14T10:33:25.768505088+05:30" + version: 10.14.3 +digest: sha256:f523a047b9e2ae36143e7ae661f0a08ebfa4df65f1b7e757f4acd6888dd7642f +generated: "2022-08-24T18:21:08.145589508+05:30" diff --git a/charts/healthchecks/Chart.yaml b/charts/healthchecks/Chart.yaml index 337d47a..335f235 100644 --- a/charts/healthchecks/Chart.yaml +++ b/charts/healthchecks/Chart.yaml @@ -1,10 +1,10 @@ -version: 1.0.5 +version: 1.0.6 apiVersion: v2 name: healthchecks description: A Helm chart for Kubernetes maintainers: - - email: pratik@improeised.com - name: praitk + - email: rakshit@improwised.com + name: rakshit # A chart can be either an 'application' or a 'library' chart. # # Application charts are a collection of templates that can be packaged into versioned archives @@ -26,6 +26,6 @@ sources: - https://github.com/healthchecks/healthchecks dependencies: - name: postgresql - version: 9.1.1 + version: 10.14.3 repository: https://charts.bitnami.com/bitnami condition: postgresql.enabled,global.postgresql.enabled diff --git a/charts/healthchecks/templates/_helpers.tpl b/charts/healthchecks/templates/_helpers.tpl index 2949b96..f7781da 100644 --- a/charts/healthchecks/templates/_helpers.tpl +++ b/charts/healthchecks/templates/_helpers.tpl @@ -50,3 +50,40 @@ Selector labels app.kubernetes.io/name: {{ include "healthchecks.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} + +{{/* +Return the appropriate apiVersion for ingress. +*/}} +{{- define "ingress.apiVersion" -}} +{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.Version -}} +{{- print "extensions/v1beta1" -}} +{{- else if semverCompare "<1.19-0" .Capabilities.KubeVersion.Version -}} +{{- print "networking.k8s.io/v1beta1" -}} +{{- else -}} +{{- print "networking.k8s.io/v1" -}} +{{- end -}} +{{- end -}} + +{{- define "ingress.backend" -}} +{{- $apiVersion := (include "ingress.apiVersion" .context) -}} +{{- if or (eq $apiVersion "extensions/v1beta1") (eq $apiVersion "networking.k8s.io/v1beta1") -}} +serviceName: {{ .serviceName }} +servicePort: {{ .servicePort }} +{{- else -}} +service: + name: {{ .serviceName }} + port: + {{- if typeIs "string" .servicePort }} + name: {{ .servicePort }} + {{- else if or (typeIs "int" .servicePort) (typeIs "float64" .servicePort) }} + number: {{ .servicePort | int }} + {{- end }} +{{- end -}} +{{- end -}} + +{{- define "ingress.pathtype" -}} +{{- $apiVersion := (include "ingress.apiVersion" .) -}} +{{- if (eq $apiVersion "networking.k8s.io/v1") -}} +pathType: ImplementationSpecific +{{- end -}} +{{- end -}} diff --git a/charts/healthchecks/templates/ingress.yaml b/charts/healthchecks/templates/ingress.yaml index 1516ec8..5d908e6 100644 --- a/charts/healthchecks/templates/ingress.yaml +++ b/charts/healthchecks/templates/ingress.yaml @@ -1,11 +1,7 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "healthchecks.fullname" . -}} {{- $svcPort := .Values.service.port -}} -{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 -{{- end }} +apiVersion: {{ include "ingress.apiVersion" . }} kind: Ingress metadata: name: {{ $fullName }} @@ -18,24 +14,23 @@ metadata: spec: {{- if .Values.ingress.tls }} tls: - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . | quote }} - {{- end }} - secretName: {{ .secretName }} + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} {{- end }} + secretName: {{ .secretName }} + {{- end }} {{- end }} rules: - {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} - http: - paths: - {{- range .paths }} - - path: {{ . }} - backend: - serviceName: {{ $fullName }} - servicePort: {{ $svcPort }} - {{- end }} - {{- end }} + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: {{- include "ingress.backend" (dict "serviceName" $fullName "servicePort" $svcPort "context" $) | nindent 10 }} + {{- end }} {{- end }} +{{- end }}