|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "redis-cluster.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create a default fully qualified app name. |
| 10 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 11 | +If release name contains chart name it will be used as a full name. |
| 12 | +*/}} |
| 13 | +{{- define "redis-cluster.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride }} |
| 15 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
| 16 | +{{- else }} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride }} |
| 18 | +{{- if contains $name .Release.Name }} |
| 19 | +{{- .Release.Name | trunc 63 | trimSuffix "-" }} |
| 20 | +{{- else }} |
| 21 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} |
| 22 | +{{- end }} |
| 23 | +{{- end }} |
| 24 | +{{- end }} |
| 25 | + |
| 26 | +{{/* |
| 27 | +Create chart name and version as used by the chart label. |
| 28 | +*/}} |
| 29 | +{{- define "redis-cluster.chart" -}} |
| 30 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 31 | +{{- end }} |
| 32 | + |
| 33 | +{{/* |
| 34 | +Common labels |
| 35 | +*/}} |
| 36 | +{{- define "redis-cluster.labels" -}} |
| 37 | +helm.sh/chart: {{ include "redis-cluster.chart" . }} |
| 38 | +{{ include "redis-cluster.selectorLabels" . }} |
| 39 | +{{- if .Chart.AppVersion }} |
| 40 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 41 | +{{- end }} |
| 42 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 43 | +{{- end }} |
| 44 | + |
| 45 | +{{/* |
| 46 | +Selector labels |
| 47 | +*/}} |
| 48 | +{{- define "redis-cluster.selectorLabels" -}} |
| 49 | +app.kubernetes.io/name: {{ include "redis-cluster.name" . }} |
| 50 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 51 | +{{- end }} |
| 52 | + |
| 53 | +{{/* |
| 54 | +Create the name of the service account to use |
| 55 | +*/}} |
| 56 | +{{- define "redis-cluster.serviceAccountName" -}} |
| 57 | +{{- if .Values.serviceAccount.create }} |
| 58 | +{{- default (include "redis-cluster.fullname" .) .Values.serviceAccount.name }} |
| 59 | +{{- else }} |
| 60 | +{{- default "default" .Values.serviceAccount.name }} |
| 61 | +{{- end }} |
| 62 | +{{- end }} |
| 63 | + |
| 64 | +{{/* |
| 65 | +replicaCount = master + master * replica |
| 66 | +*/}} |
| 67 | +{{- define "redis-cluster.replicaCount" -}} |
| 68 | +{{- mul .Values.cluster.master .Values.cluster.replicas | add .Values.cluster.master }} |
| 69 | +{{- end }} |
| 70 | + |
| 71 | +{{- define "redis-cluster.addToConfig" -}} |
| 72 | +{{- if eq (printf "%s" .value) "" }} |
| 73 | +{{ .key }} "" |
| 74 | +{{- else }} |
| 75 | +{{ .key }} {{ .value }} |
| 76 | +{{- end }} |
| 77 | +{{- end }} |
| 78 | + |
| 79 | +{{- define "redis-cluster.getHostPorts" -}} |
| 80 | +{{- $hostPorts := "" -}} |
| 81 | +{{- range $i := until (include "redis-cluster.replicaCount" . | int) }} |
| 82 | +{{- $hostPorts = printf "%s%s-%d.%s-headless.%s.svc.cluster.local:%d " $hostPorts (include "redis-cluster.name" $) $i (include "redis-cluster.name" $) $.Release.Namespace ($.Values.redis.port | int) }} |
| 83 | +{{- end }} |
| 84 | +{{- $hostPorts }} |
| 85 | +{{- end }} |
| 86 | + |
| 87 | +{{- define "redis-cluster.getRedisAddrs" -}} |
| 88 | +{{- $hostPorts := "" -}} |
| 89 | +{{- range $i := until (include "redis-cluster.replicaCount" . | int) }} |
| 90 | +{{- $hostPorts = printf "%sredis://%s-%d.%s-headless.%s.svc.cluster.local:%d " $hostPorts (include "redis-cluster.name" $) $i (include "redis-cluster.name" $) $.Release.Namespace ($.Values.redis.port | int) }} |
| 91 | +{{- end }} |
| 92 | +{{- $hostPorts | trimSuffix " " }} |
| 93 | +{{- end }} |
0 commit comments