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() {