mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-05 23:06:21 -03:00
more redis impl work
This commit is contained in:
@@ -28,9 +28,13 @@ probes:
|
||||
# -- Redis dependency configuration
|
||||
# @default -- See below
|
||||
redis:
|
||||
enabled: false
|
||||
existingSecret: "rediscreds"
|
||||
# -- can be used to make an easy accessable note which URLS to use to access the DB.
|
||||
url: {}
|
||||
manifests:
|
||||
enabled: false
|
||||
main:
|
||||
enabled: true
|
||||
# -- can be used to make an easy accessable note which URLS to use to access the DB.
|
||||
url: {}
|
||||
redis:
|
||||
replicas: 2
|
||||
sentinel:
|
||||
replicas: 3
|
||||
auth:
|
||||
enabled: false
|
||||
|
||||
67
library/common/templates/class/_redis.tpl
Normal file
67
library/common/templates/class/_redis.tpl
Normal file
@@ -0,0 +1,67 @@
|
||||
{{- define "tc.v1.common.class.redis.cluster" -}}
|
||||
{{- $values := .Values.redis -}}
|
||||
|
||||
{{- if hasKey . "ObjectValues" -}}
|
||||
{{- with .ObjectValues.redis -}}
|
||||
{{- $values = . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $redisClusterName := $values.name -}}
|
||||
{{- $redisClusterLabels := $values.labels -}}
|
||||
{{- $redisClusterAnnotations := $values.annotations }}
|
||||
|
||||
---
|
||||
apiVersion: {{ include "tc.v1.common.capabilities.redis.failover.apiVersion" $ }}
|
||||
kind: RedisFailover
|
||||
metadata:
|
||||
name: {{ $redisClusterName }}
|
||||
{{- $labels := (mustMerge ($redisClusterLabels | default dict) (include "ix.v1.common.labels" $ | fromYaml)) -}}
|
||||
{{- with (include "ix.v1.common.util.labels.render" (dict "root" $ "labels" $labels) | trim) }}
|
||||
labels:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
{{- $annotations := (mustMerge ($redisClusterAnnotations | default dict) (include "ix.v1.common.annotations" $ | fromYaml)) -}}
|
||||
{{- with (include "ix.v1.common.util.annotations.render" (dict "root" $ "annotations" $annotations) | trim) }}
|
||||
annotations:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
sentinel:
|
||||
replicas: {{ $values.sentinel.replicas }}
|
||||
redis:
|
||||
replicas: {{ $values.redis.replicas }}
|
||||
{{- if $values.auth.enabled }}
|
||||
auth:
|
||||
secretPath: {{ $redisClusterName }}-rediscreds
|
||||
{{- end }}
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
labels:
|
||||
{{- include "tc.common.labels" . | nindent 4 }}
|
||||
name: {{ $redisClusterName }}-rediscreds
|
||||
{{- $dbprevious := lookup "v1" "Secret" .Release.Namespace "rediscreds" }}
|
||||
{{- $dbPass := "" }}
|
||||
{{- $dbIndex := default "0" .Values.redis.redisDatabase }}
|
||||
data:
|
||||
{{- if $dbprevious }}
|
||||
{{- $dbPass = ( index $dbprevious.data "redis-password" ) | b64dec }}
|
||||
redis-password: {{ ( index $dbprevious.data "redis-password" ) }}
|
||||
{{- else }}
|
||||
{{- $dbPass = randAlphaNum 50 }}
|
||||
redis-password: {{ $dbPass | b64enc | quote }}
|
||||
{{- end }}
|
||||
url: {{ ( printf "redis://%v:%v@%v-redis:6379/%v" .Values.redis.redisUsername $dbPass .Release.Name $dbIndex ) | b64enc | quote }}
|
||||
plainhostpass: {{ ( printf "%v:%v@%v-redis" .Values.redis.redisUsername $dbPass .Release.Name ) | b64enc | quote }}
|
||||
plainporthost: {{ ( printf "%v-%v:6379" .Release.Name "redis" ) | b64enc | quote }}
|
||||
plainhost: {{ ( printf "%v-%v" .Release.Name "redis" ) | b64enc | quote }}
|
||||
type: Opaque
|
||||
{{- $_ := set .Values.redis "redisPassword" ( $dbPass | quote ) }}
|
||||
{{- $_ := set .Values.redis.url "plain" ( ( printf "%v-%v" .Release.Name "redis" ) | quote ) }}
|
||||
{{- $_ := set .Values.redis.url "plainhost" ( ( printf "%v-%v" .Release.Name "redis" ) | quote ) }}
|
||||
{{- $_ := set .Values.redis.url "plainport" ( ( printf "%v-%v:6379" .Release.Name "redis" ) | quote ) }}
|
||||
{{- $_ := set .Values.redis.url "plainporthost" ( ( printf "%v-%v:6379" .Release.Name "redis" ) | quote ) }}
|
||||
|
||||
{{- end -}}
|
||||
@@ -33,12 +33,17 @@
|
||||
{{- print "cert-manager.io/v1" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Return the appropriate apiVersion for Cert-Manager certificates */}}
|
||||
{{/* Return the appropriate apiVersion forcnpg clusters */}}
|
||||
{{- define "tc.v1.common.capabilities.cnpg.cluster.apiVersion" -}}
|
||||
{{- print "postgresql.cnpg.io/v1" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Return the appropriate apiVersion for Cert-Manager certificates */}}
|
||||
{{/* Return the appropriate apiVersion for cnpg poolers */}}
|
||||
{{- define "tc.v1.common.capabilities.cnpg.pooler.apiVersion" -}}
|
||||
{{- print "postgresql.cnpg.io/v1" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Return the appropriate apiVersion for redis failover objects */}}
|
||||
{{- define "tc.v1.common.capabilities.redis.failover.apiVersion" -}}
|
||||
{{- print "databases.spotahome.com/v1" -}}
|
||||
{{- end -}}
|
||||
|
||||
23
library/common/templates/lib/util/_primary_redis.tpl
Normal file
23
library/common/templates/lib/util/_primary_redis.tpl
Normal file
@@ -0,0 +1,23 @@
|
||||
{{/* Return the name of the primary redis object */}}
|
||||
{{- define "tc.v1.common.lib.util.redis.primary" -}}
|
||||
{{- $rediss := .Values.redis -}}
|
||||
|
||||
{{- $enabledredises := dict -}}
|
||||
{{- range $name, $redis := $rediss -}}
|
||||
{{- if $redis.enabled -}}
|
||||
{{- $_ := set $enabledredises $name . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $result := "" -}}
|
||||
{{- range $name, $redis := $enabledredises -}}
|
||||
{{- if and (hasKey $redis "primary") $redis.primary -}}
|
||||
{{- $result = $name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $result -}}
|
||||
{{- $result = keys $enabledredises | first -}}
|
||||
{{- end -}}
|
||||
{{- $result -}}
|
||||
{{- end -}}
|
||||
26
library/common/templates/spawner/_redis.tpl
Normal file
26
library/common/templates/spawner/_redis.tpl
Normal file
@@ -0,0 +1,26 @@
|
||||
{{/* Renders the redis objects required by the chart */}}
|
||||
{{- define "tc.v1.common.spawner.redis" -}}
|
||||
{{/* Generate named redises as required */}}
|
||||
{{- range $name, $redis := .Values.redis -}}
|
||||
{{- if $redis.enabled -}}
|
||||
{{- $redisValues := $redis -}}
|
||||
{{- $redisName := include "ix.v1.common.names.fullname" $ -}}
|
||||
|
||||
{{/* set defaults */}}
|
||||
{{- if and (not $redisValues.nameOverride) (ne $name (include "tc.v1.common.lib.util.redis.primary" $)) -}}
|
||||
{{- $_ := set $redisValues "nameOverride" $name -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $redisValues.nameOverride -}}
|
||||
{{- $redisName = printf "%v-%v" $redisName $redisValues.nameOverride -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $redisName = printf "redis-%v" $redisName -}}
|
||||
|
||||
{{- $_ := set $redisValues "name" $redisName -}}
|
||||
|
||||
{{- include "tc.v1.common.class.redis.pooler" $ -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -445,7 +445,8 @@ systemContainers:
|
||||
volumeMounts:
|
||||
- inherit: "setPermissions"
|
||||
redis-wait:
|
||||
enabled: "{{ if .Values.redis.enabled }}true{{ else }}false{{ end }}"
|
||||
enabled: false
|
||||
#enabled: '{{ $result := false }}{{ range .Values.cnpg }}{{ if .enabled }}{{ $result = true }}{{ end }}{{ end }}{{ $result }}'
|
||||
imageSelector: redisClientImage
|
||||
securityContext:
|
||||
runAsUser: 568
|
||||
@@ -454,32 +455,35 @@ systemContainers:
|
||||
runAsNonRoot: true
|
||||
resources:
|
||||
inherit: true
|
||||
env:
|
||||
REDIS_HOST:
|
||||
secretKeyRef:
|
||||
name: rediscreds
|
||||
key: plainhost
|
||||
REDIS_PASSWORD:
|
||||
secretKeyRef:
|
||||
name: rediscreds
|
||||
key: redis-password
|
||||
REDIS_PORT:
|
||||
value: "6379"
|
||||
command:
|
||||
- "/bin/sh"
|
||||
- "-c"
|
||||
- |
|
||||
/bin/bash <<'EOF'
|
||||
{{ range $name, $redis := .Values.redis }}
|
||||
{{ if $redis.enabled }}
|
||||
echo "Executing DB waits..."
|
||||
[[ -n "$REDIS_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_PASSWORD";
|
||||
{{ $redisName := include "ix.v1.common.names.fullname" $ }}
|
||||
{{ $nameOverride := $redis.nameOverride }}
|
||||
|
||||
{{ if and (not $redis.nameOverride ) (ne $name (include "tc.v1.common.lib.util.redis.primary" $)) }}
|
||||
{{ $_ := set $redis.nameOverride $name }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $redis.nameOverride }}
|
||||
{{ $redisName = printf "%v-%v" $redisName $nameOverride }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{ if $redis.auth }}export REDISCLI_AUTH="{{ }}";{{ end }}
|
||||
export LIVE=false;
|
||||
until "$LIVE";
|
||||
do
|
||||
response=$(
|
||||
timeout -s 3 2 \
|
||||
redis-cli \
|
||||
-h "$REDIS_HOST" \
|
||||
-p "$REDIS_PORT" \
|
||||
-h "{{ }}" \
|
||||
-p "{{ }}" \
|
||||
ping
|
||||
)
|
||||
if [ "$response" == "PONG" ] || [ "$response" == "LOADING Redis is loading the dataset in memory" ]; then
|
||||
@@ -492,6 +496,13 @@ systemContainers:
|
||||
sleep 10
|
||||
fi;
|
||||
done
|
||||
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
|
||||
|
||||
EOF
|
||||
mariadb-wait:
|
||||
enabled: "{{ if .Values.mariadb.enabled }}true{{ else }}false{{end}}"
|
||||
@@ -1071,12 +1082,16 @@ cnpg:
|
||||
# -- Redis dependency configuration
|
||||
# @default -- See below
|
||||
redis:
|
||||
enabled: false
|
||||
existingSecret: "rediscreds"
|
||||
# -- can be used to make an easy accessable note which URLS to use to access the DB.
|
||||
url: {}
|
||||
manifests:
|
||||
main:
|
||||
enabled: false
|
||||
# -- can be used to make an easy accessable note which URLS to use to access the DB.
|
||||
url: {}
|
||||
redis:
|
||||
replicas: 2
|
||||
sentinel:
|
||||
replicas: 3
|
||||
auth:
|
||||
enabled: false
|
||||
|
||||
# -- mariadb dependency configuration
|
||||
# @default -- See below
|
||||
|
||||
Reference in New Issue
Block a user