From 346a1d316bdb0c58685683c8052cfd55e5f52223 Mon Sep 17 00:00:00 2001 From: Lucas Hahn Date: Fri, 9 Jul 2021 16:39:56 +0200 Subject: [PATCH] add redis-cluster support --- Chart.yaml | 4 ++++ templates/_helpers.tpl | 22 +++++++++++++++++++++- templates/gitea/init.yaml | 21 +++++++++++++++++++++ values.yaml | 21 +++++++++++++++++++-- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/Chart.yaml b/Chart.yaml index 325ffad..b43405e 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -38,6 +38,10 @@ dependencies: repository: https://charts.bitnami.com/bitnami version: 6.2.3 condition: redis-cluster.enabled +- name: redis + repository: https://charts.bitnami.com/bitnami + version: 14.6.6 + condition: redis.enabled - name: mysql repository: https://charts.bitnami.com/bitnami version: 6.14.10 diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 4182bf1..269e15a 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -112,7 +112,27 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end -}} {{- define "redis.dns" -}} -{{- printf "redis://%s-redis-cluster.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s" .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "redis-cluster").service.port -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{- printf "redis://:%s@%s-redis-cluster-headless.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s" (index .Values "redis-cluster").global.redis.password .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "redis-cluster").service.port -}} +{{- else if .Values.redis.enabled -}} +{{- printf "redis://:%s@%s-redis-master.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s" .Values.redis.global.redis.password .Release.Name .Release.Namespace .Values.clusterDomain .Values.redis.master.service.port -}} +{{- end -}} +{{- end -}} + +{{- define "redis.port" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{ (index .Values "redis-cluster").service.port }} +{{- else if .Values.redis.enabled -}} +{{ .Values.redis.master.service.port }} +{{- end -}} +{{- end -}} + +{{- define "redis.servicename" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{- printf "%s-redis-cluster-headless.%s.svc.%s" .Release.Name .Release.Namespace .Values.clusterDomain -}} +{{- else if .Values.redis.enabled -}} +{{- printf "%s-redis-master.%s.svc.%s" .Release.Name .Release.Namespace .Values.clusterDomain -}} +{{- end -}} {{- end -}} {{- define "gitea.default_domain" -}} diff --git a/templates/gitea/init.yaml b/templates/gitea/init.yaml index 8137d67..ea6b46f 100644 --- a/templates/gitea/init.yaml +++ b/templates/gitea/init.yaml @@ -60,6 +60,27 @@ stringData: test_db_connection {{- end }} + {{- if include "redis.servicename" . }} + function test_redis_connection() { + local RETRY=0 + local MAX=30 + + echo 'Wait for redis to become avialable...' + until [ "${RETRY}" -ge "${MAX}" ]; do + nc -vz -w2 {{ include "redis.servicename" . }} {{ include "redis.port" . }} && break + RETRY=$[${RETRY}+1] + echo "...not ready yet (${RETRY}/${MAX})" + done + + if [ "${RETRY}" -ge "${MAX}" ]; then + echo "Redis not reachable after '${MAX}' attempts!" + exit 1 + fi + } + + test_redis_connection + {{- end }} + echo '==== BEGIN GITEA CONFIGURATION ====' gitea migrate diff --git a/values.yaml b/values.yaml index 17325eb..e5e34a5 100644 --- a/values.yaml +++ b/values.yaml @@ -2,7 +2,7 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. -replicaCount: 2 +replicaCount: 1 clusterDomain: cluster.local @@ -114,10 +114,16 @@ statefulset: persistence: enabled: true - existingClaim: gitea-data-test + # existingClaim: + size: 10Gi + accessModes: + - ReadWriteOnce + labels: {} + annotations: {} # storageClass: # subPath: + # additional volumes to add to the Gitea statefulset. extraVolumes: # - name: postgres-ssl-vol @@ -245,6 +251,17 @@ memcached: service: port: 11211 +redis: + enabled: false + global: + redis: + password: gitea + master: + service: + port: 6379 + replica: + replicaCount: 2 + redis-cluster: enabled: false global: