From 704e13bbe8966ccbc814c2ddd195d256949fb568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gre=CC=81goire=20Compagnon?= Date: Mon, 7 Aug 2023 19:30:09 +0200 Subject: [PATCH] Automatic postgresql host discovery --- kubernetes/templates/_helpers.tpl | 11 +++++++++++ kubernetes/templates/configmap.yaml | 9 +++++++++ kubernetes/templates/deployment.yaml | 2 +- kubernetes/values.yaml | 3 ++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/kubernetes/templates/_helpers.tpl b/kubernetes/templates/_helpers.tpl index 52158b78..75160e63 100644 --- a/kubernetes/templates/_helpers.tpl +++ b/kubernetes/templates/_helpers.tpl @@ -14,3 +14,14 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- $name := default .Chart.Name .Values.nameOverride -}} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} + +{{/* +Return postgresql host (autogenerated if `postgresql.enabled, user provided else) +*/}} +{{- define "invidious.pghost" -}} +{{- if empty .Values.config.db.host -}} +{{ .Release.Name }}-postgresql +{{- else -}} +{{ .Values.config.db.host }} +{{- end -}} +{{- end -}} diff --git a/kubernetes/templates/configmap.yaml b/kubernetes/templates/configmap.yaml index 58542a31..2b902fd9 100644 --- a/kubernetes/templates/configmap.yaml +++ b/kubernetes/templates/configmap.yaml @@ -1,3 +1,12 @@ +{{- define "invidious.pghost_inject" -}} +{{- if empty .Values.config.db.host -}} +config: + db: + host: {{ template "invidious.pghost" . }} +{{- end -}} +{{- end -}} +{{ $_ := mergeOverwrite .Values (include "invidious.pghost_inject" . | fromYaml) -}} + apiVersion: v1 kind: ConfigMap metadata: diff --git a/kubernetes/templates/deployment.yaml b/kubernetes/templates/deployment.yaml index 4ef4fce4..f068cf14 100644 --- a/kubernetes/templates/deployment.yaml +++ b/kubernetes/templates/deployment.yaml @@ -29,7 +29,7 @@ spec: args: - /bin/sh - -c - - until pg_isready -h {{ .Values.config.db.host }} -p {{ .Values.config.db.port }} -U {{ .Values.config.db.user }}; do echo waiting for database; sleep 2; done; + - until pg_isready -h {{ template "invidious.pghost" . }} -p {{ .Values.config.db.port }} -U {{ .Values.config.db.user }}; do echo waiting for database; sleep 2; done; - name: db-migration image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} diff --git a/kubernetes/values.yaml b/kubernetes/values.yaml index 279c5714..3f4c2f08 100644 --- a/kubernetes/values.yaml +++ b/kubernetes/values.yaml @@ -65,7 +65,8 @@ config: db: user: kemal password: kemal - host: invidious-postgresql + #-- Leave empty if you use embeded postgresql server + host: port: 5432 dbname: invidious full_refresh: false