From d35de55248062b217e6f42958e872b60821eeb79 Mon Sep 17 00:00:00 2001 From: luhahn Date: Wed, 2 Mar 2022 08:25:49 +0800 Subject: [PATCH] Remove db connection check (#299) This will remove the db connection check, which has caused some trouble in the past. It will now simply run _gitea migrate_ and output a message, if the database is not available. Co-authored-by: Lucas Hahn Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/299 Reviewed-by: justusbunsi Reviewed-by: Lunny Xiao Co-authored-by: luhahn Co-committed-by: luhahn --- templates/_helpers.tpl | 24 ------------------------ templates/gitea/init.yaml | 30 +++++++----------------------- 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 40471ee..2d12b81 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -61,30 +61,6 @@ app.kubernetes.io/name: {{ include "gitea.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end -}} -{{- define "db.servicename" -}} -{{- if .Values.postgresql.enabled -}} -{{- printf "%s-postgresql" .Release.Name -}} -{{- else if .Values.mysql.enabled -}} -{{- printf "%s-mysql" .Release.Name -}} -{{- else if .Values.mariadb.enabled -}} -{{- printf "%s-mariadb" .Release.Name -}} -{{- else if ne .Values.gitea.config.database.DB_TYPE "sqlite3" -}} -{{- $parts := split ":" .Values.gitea.config.database.HOST -}} -{{- printf "%s %s" $parts._0 $parts._1 -}} -{{- end -}} -{{- end -}} - -{{- define "db.port" -}} -{{- if .Values.postgresql.enabled -}} -{{ .Values.postgresql.global.postgresql.servicePort }} -{{- else if .Values.mysql.enabled -}} -{{ .Values.mysql.service.port }} -{{- else if .Values.mariadb.enabled -}} -{{ .Values.mariadb.primary.service.port }} -{{- else -}} -{{- end -}} -{{- end -}} - {{- define "postgresql.dns" -}} {{- printf "%s-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain .Values.postgresql.global.postgresql.servicePort -}} {{- end -}} diff --git a/templates/gitea/init.yaml b/templates/gitea/init.yaml index 5854c7a..00af29b 100644 --- a/templates/gitea/init.yaml +++ b/templates/gitea/init.yaml @@ -40,31 +40,15 @@ stringData: set -euo pipefail - {{- if include "db.servicename" . }} - # Connection retry inspired by https://gist.github.com/dublx/e99ea94858c07d2ca6de - function test_db_connection() { - local RETRY=0 - local MAX=30 - - echo 'Wait for database to become avialable...' - until [ "${RETRY}" -ge "${MAX}" ]; do - nc -vz -w2 {{ include "db.servicename" . }} {{ include "db.port" . }} && break - RETRY=$[${RETRY}+1] - echo "...not ready yet (${RETRY}/${MAX})" - done - - if [ "${RETRY}" -ge "${MAX}" ]; then - echo "Database not reachable after '${MAX}' attempts!" - exit 1 - fi - } - - test_db_connection - {{- end }} - echo '==== BEGIN GITEA CONFIGURATION ====' - gitea migrate + { # try + gitea migrate + } || { # catch + echo "Gitea migrate might fail due to database connection...This init-container will try again in a few seconds" + exit 1 + } + {{- if or .Values.gitea.admin.existingSecret (and .Values.gitea.admin.username .Values.gitea.admin.password) }} function configure_admin_user() {