|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "kafka.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 35 | 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 "kafka.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride }} |
| 15 | +{{- .Values.fullnameOverride | trunc 35 | trimSuffix "-" }} |
| 16 | +{{- else }} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride }} |
| 18 | +{{- if contains $name .Release.Name }} |
| 19 | +{{- .Release.Name | trunc 35 | trimSuffix "-" }} |
| 20 | +{{- else }} |
| 21 | +{{- printf "%s-%s" .Release.Name $name | trunc 35 | trimSuffix "-" }} |
| 22 | +{{- end }} |
| 23 | +{{- end }} |
| 24 | +{{- end }} |
| 25 | + |
| 26 | +{{/* |
| 27 | +Create chart name and version as used by the chart label. |
| 28 | +*/}} |
| 29 | +{{- define "kafka.chart" -}} |
| 30 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 35 | trimSuffix "-" }} |
| 31 | +{{- end }} |
| 32 | + |
| 33 | +{{/* |
| 34 | +Common labels |
| 35 | +*/}} |
| 36 | +{{- define "kafka.labels" -}} |
| 37 | +helm.sh/chart: {{ include "kafka.chart" . }} |
| 38 | +{{ include "kafka.selectorLabels" . }} |
| 39 | +{{- if .Chart.AppVersion }} |
| 40 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 41 | +{{- end }} |
| 42 | +app.kubernetes.io/part-of: {{ include "kafka.name" . }} |
| 43 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 44 | +{{- with .Values.global.additionalLabels }} |
| 45 | +{{ toYaml . }} |
| 46 | +{{- end }} |
| 47 | +{{- end }} |
| 48 | + |
| 49 | +{{/* |
| 50 | +Selector labels |
| 51 | +*/}} |
| 52 | +{{- define "kafka.selectorLabels" -}} |
| 53 | +app.kubernetes.io/name: {{ include "kafka.name" . }} |
| 54 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 55 | +{{- end }} |
| 56 | + |
| 57 | +{{/* |
| 58 | +Create the name of the service account to use |
| 59 | +*/}} |
| 60 | +{{- define "kafka.serviceAccountName" -}} |
| 61 | +{{- if .Values.serviceAccount.create }} |
| 62 | +{{- default (include "kafka.fullname" .) .Values.serviceAccount.name }} |
| 63 | +{{- else }} |
| 64 | +{{- default "default" .Values.serviceAccount.name }} |
| 65 | +{{- end }} |
| 66 | +{{- end }} |
| 67 | + |
| 68 | +{{/* |
| 69 | +Allow the release namespace to be overridden for multi-namespace deployments in combined charts |
| 70 | +*/}} |
| 71 | +{{- define "kafka.namespace" -}} |
| 72 | +{{- if .Values.namespaceOverride }} |
| 73 | +{{- .Values.namespaceOverride }} |
| 74 | +{{- else }} |
| 75 | +{{- .Release.Namespace }} |
| 76 | +{{- end }} |
| 77 | +{{- end }} |
| 78 | + |
| 79 | +{{/* |
| 80 | +kafka image |
| 81 | +*/}} |
| 82 | +{{- define "kafka.kafkaImage" -}} |
| 83 | +{{- $imageTag := default .Chart.AppVersion .Values.image.tag }} |
| 84 | +{{- printf "%s:%s" .Values.image.repository $imageTag }} |
| 85 | +{{- end }} |
| 86 | + |
| 87 | +{{/* |
| 88 | +kafka.entrypoint.configmapName |
| 89 | +*/}} |
| 90 | +{{- define "kafka.entrypoint.configmapName" -}} |
| 91 | +{{ include "kafka.fullname" .}}-entrypoint |
| 92 | +{{- end }} |
| 93 | + |
| 94 | +{{/* |
| 95 | +kafka-controller |
| 96 | +*/}} |
| 97 | +{{- define "kafka.controller.fullname" -}} |
| 98 | +{{- printf "%s-controller" (include "kafka.fullname" .) }} |
| 99 | +{{- end }} |
| 100 | + |
| 101 | +{{/* |
| 102 | +kafka-broker |
| 103 | +*/}} |
| 104 | +{{- define "kafka.broker.fullname" -}} |
| 105 | + {{- printf "%s-broker" (include "kafka.fullname" .) }} |
| 106 | +{{- end }} |
| 107 | + |
| 108 | +{{/* |
| 109 | +kafka-ui |
| 110 | +*/}} |
| 111 | +{{- define "kafka.ui.fullname" -}} |
| 112 | +{{- printf "%s-ui" (include "kafka.fullname" .) }} |
| 113 | +{{- end }} |
| 114 | + |
| 115 | +{{/* |
| 116 | +kafka-exporter |
| 117 | +*/}} |
| 118 | +{{- define "kafka.exporter.fullname" -}} |
| 119 | +{{- printf "%s-exporter" (include "kafka.fullname" .) }} |
| 120 | +{{- end }} |
| 121 | + |
| 122 | +{{/* |
| 123 | +kafka clusterId SecretName |
| 124 | +*/}} |
| 125 | +{{- define "kafka.clusterId.SecretName" -}} |
| 126 | +{{- printf "%s-cluster-id" (include "kafka.fullname" .) }} |
| 127 | +{{- end }} |
| 128 | + |
| 129 | +{{/* |
| 130 | +kafka combinedMode |
| 131 | +*/}} |
| 132 | +{{- define "kafka.combinedMode" -}} |
| 133 | +{{- if .Values.controller.enabled -}} |
| 134 | +{{- print "false" -}} |
| 135 | +{{- else -}} |
| 136 | +{{- print "true" -}} |
| 137 | +{{- end -}} |
| 138 | +{{- end -}} |
| 139 | + |
| 140 | +{{/* |
| 141 | +kafka clusterDomain |
| 142 | +*/}} |
| 143 | +{{- define "kafka.clusterDomain" -}} |
| 144 | +{{- default "cluster.local" .Values.clusterDomain -}} |
| 145 | +{{- end -}} |
| 146 | + |
| 147 | +{{/* |
| 148 | +kafka broker headless serviceName |
| 149 | +*/}} |
| 150 | +{{- define "kafka.broker.headless.serviceName" -}} |
| 151 | +{{- printf "%s-headless" (include "kafka.fullname" .) }} |
| 152 | +{{- end }} |
| 153 | + |
| 154 | + |
| 155 | +{{/* |
| 156 | +kafka.controller.headless.serviceName |
| 157 | +*/}} |
| 158 | +{{- define "kafka.controller.headless.serviceName" -}} |
| 159 | +{{- printf "%s" (include "kafka.controller.fullname" .) }} |
| 160 | +{{- end }} |
| 161 | + |
| 162 | +{{/* |
| 163 | +kafka.controller.quorum.voters |
| 164 | +*/}} |
| 165 | +{{- define "kafka.controller.quorum.voters" -}} |
| 166 | +{{- $fullName := include "kafka.controller.fullname" . -}} |
| 167 | +{{- $serviceName := include "kafka.controller.headless.serviceName" . -}} |
| 168 | +{{- $replicaCount := int .Values.controller.replicaCount -}} |
| 169 | +{{- if not .Values.controller.enabled -}} |
| 170 | + {{- $replicaCount = int .Values.broker.replicaCount -}} |
| 171 | + {{- $fullName = include "kafka.broker.fullname" . -}} |
| 172 | + {{- $serviceName = include "kafka.broker.headless.serviceName" . -}} |
| 173 | +{{- end -}} |
| 174 | +{{- $namespace := include "kafka.namespace" . -}} |
| 175 | +{{- $clusterDomain := include "kafka.clusterDomain" . -}} |
| 176 | +{{- $port := int .Values.controller.containerPort -}} |
| 177 | +{{- $suffix := printf "%s.%s.svc.%s:%d" $serviceName $namespace $clusterDomain $port -}} |
| 178 | + {{- $servers := list -}} |
| 179 | + {{- range $i := until (int $replicaCount) -}} |
| 180 | + {{- $servers = printf "%d@%s-%d.%s" $i $fullName $i $suffix | append $servers -}} |
| 181 | + {{- end -}} |
| 182 | +{{ join "," $servers }} |
| 183 | +{{- end -}} |
0 commit comments