155 lines
5.0 KiB
Smarty
155 lines
5.0 KiB
Smarty
{{/* Chart name */}}
|
|
{{- define "redis-cluster.name" -}}
|
|
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
|
|
{{- end -}}
|
|
|
|
{{/* Fully qualified app name */}}
|
|
{{- define "redis-cluster.fullname" -}}
|
|
{{- if .Values.fullnameOverride -}}
|
|
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
|
|
{{- else -}}
|
|
{{- $name := default .Chart.Name .Values.nameOverride -}}
|
|
{{- if contains $name .Release.Name -}}
|
|
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
|
|
{{- else -}}
|
|
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Chart label */}}
|
|
{{- define "redis-cluster.chart" -}}
|
|
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
|
|
{{- end -}}
|
|
|
|
{{/* Common labels */}}
|
|
{{- define "redis-cluster.labels" -}}
|
|
helm.sh/chart: {{ include "redis-cluster.chart" . }}
|
|
{{ include "redis-cluster.selectorLabels" . }}
|
|
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
|
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
|
{{- end -}}
|
|
|
|
{{/* Selector labels */}}
|
|
{{- define "redis-cluster.selectorLabels" -}}
|
|
app.kubernetes.io/name: {{ include "redis-cluster.name" . }}
|
|
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
{{- end -}}
|
|
|
|
{{/*
|
|
Headless service DNS name. Deliberately stop at .svc: the cluster DNS suffix is
|
|
not necessarily cluster.local, and Kubernetes expands this portable name using
|
|
the pod's search domains.
|
|
*/}}
|
|
{{- define "redis-cluster.headlessFqdn" -}}
|
|
{{ include "redis-cluster.fullname" . }}-headless.{{ .Release.Namespace }}.svc
|
|
{{- end -}}
|
|
|
|
{{/* Service account name */}}
|
|
{{- define "redis-cluster.serviceAccountName" -}}
|
|
{{- if .Values.serviceAccount.create -}}
|
|
{{- default (include "redis-cluster.fullname" .) .Values.serviceAccount.name -}}
|
|
{{- else -}}
|
|
{{- default "default" .Values.serviceAccount.name -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Secret name holding the password */}}
|
|
{{- define "redis-cluster.secretName" -}}
|
|
{{- if .Values.auth.existingSecret -}}
|
|
{{- .Values.auth.existingSecret -}}
|
|
{{- else -}}
|
|
{{- include "redis-cluster.fullname" . -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Secret key holding the password */}}
|
|
{{- define "redis-cluster.secretKey" -}}
|
|
{{- if .Values.auth.existingSecret -}}
|
|
{{- .Values.auth.existingSecretKey -}}
|
|
{{- else -}}
|
|
redis-password
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/*
|
|
Password: explicit value wins; otherwise reuse the one already in the cluster
|
|
(so upgrades don't rotate it); otherwise generate.
|
|
*/}}
|
|
{{- define "redis-cluster.password" -}}
|
|
{{- if .Values.auth.password -}}
|
|
{{- .Values.auth.password -}}
|
|
{{- else -}}
|
|
{{- $existing := lookup "v1" "Secret" .Release.Namespace (include "redis-cluster.fullname" .) -}}
|
|
{{- if and $existing $existing.data (index $existing.data "redis-password") -}}
|
|
{{- index $existing.data "redis-password" | b64dec -}}
|
|
{{- else -}}
|
|
{{- randAlphaNum 24 -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/* Total Redis nodes: shards * (one primary + replicas per shard). */}}
|
|
{{- define "redis-cluster.nodeCount" -}}
|
|
{{- mul (int .Values.cluster.shards) (add (int .Values.cluster.replicasPerShard) 1) -}}
|
|
{{- end -}}
|
|
|
|
{{/* Balanced bootstrap Service used by cluster-aware clients. */}}
|
|
{{- define "redis-cluster.bootstrapServiceName" -}}
|
|
{{- if .Values.externalAccess.enabled -}}
|
|
{{- printf "%s-external" (include "redis-cluster.fullname" .) -}}
|
|
{{- else -}}
|
|
{{- include "redis-cluster.fullname" . -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{/* RedisInsight resource name. */}}
|
|
{{- define "redis-cluster.redisInsightName" -}}
|
|
{{- printf "%s-insight" (include "redis-cluster.fullname" .) | trunc 63 | trimSuffix "-" -}}
|
|
{{- end -}}
|
|
|
|
{{/* RedisInsight labels deliberately do not match the Redis pod selector. */}}
|
|
{{- define "redis-cluster.redisInsightLabels" -}}
|
|
helm.sh/chart: {{ include "redis-cluster.chart" . }}
|
|
app.kubernetes.io/name: redisinsight
|
|
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
app.kubernetes.io/component: insight
|
|
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
|
{{- end -}}
|
|
|
|
{{- define "redis-cluster.redisInsightSelectorLabels" -}}
|
|
app.kubernetes.io/name: redisinsight
|
|
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
app.kubernetes.io/component: insight
|
|
{{- end -}}
|
|
|
|
{{/* Environment shared by Redis lifecycle scripts. */}}
|
|
{{- define "redis-cluster.commonEnv" -}}
|
|
- name: STS_NAME
|
|
value: {{ include "redis-cluster.fullname" . | quote }}
|
|
- name: HEADLESS_SERVICE
|
|
value: {{ include "redis-cluster.headlessFqdn" . | quote }}
|
|
- name: NODE_COUNT
|
|
value: {{ include "redis-cluster.nodeCount" . | quote }}
|
|
- name: SHARD_COUNT
|
|
value: {{ .Values.cluster.shards | quote }}
|
|
- name: REPLICAS_PER_SHARD
|
|
value: {{ .Values.cluster.replicasPerShard | quote }}
|
|
- name: REDIS_PORT
|
|
value: {{ .Values.redis.port | quote }}
|
|
- name: CLUSTER_BUS_PORT
|
|
value: {{ .Values.cluster.busPort | quote }}
|
|
{{- if .Values.auth.enabled }}
|
|
- name: REDIS_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: {{ include "redis-cluster.secretName" . }}
|
|
key: {{ include "redis-cluster.secretKey" . }}
|
|
- name: REDISCLI_AUTH
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: {{ include "redis-cluster.secretName" . }}
|
|
key: {{ include "redis-cluster.secretKey" . }}
|
|
{{- end }}
|
|
{{- end -}}
|