_helpers.tpl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "kafka.name" -}}
  6. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
  7. {{- end -}}
  8. {{/*
  9. Create a default fully qualified zookeeper name.
  10. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  11. */}}
  12. {{- define "kafka.zookeeper.fullname" -}}
  13. {{- if .Values.zookeeper.fullnameOverride -}}
  14. {{- .Values.zookeeper.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  15. {{- else -}}
  16. {{- $name := default "zookeeper" .Values.zookeeper.nameOverride -}}
  17. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  18. {{- end -}}
  19. {{- end -}}
  20. {{/*
  21. Create the name of the service account to use
  22. */}}
  23. {{- define "kafka.serviceAccountName" -}}
  24. {{- if .Values.serviceAccount.create -}}
  25. {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
  26. {{- else -}}
  27. {{ default "default" .Values.serviceAccount.name }}
  28. {{- end -}}
  29. {{- end -}}
  30. {{/*
  31. Return the proper Kafka image name
  32. */}}
  33. {{- define "kafka.image" -}}
  34. {{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
  35. {{- end -}}
  36. {{/*
  37. Return the proper image name (for the init container auto-discovery image)
  38. */}}
  39. {{- define "kafka.externalAccess.autoDiscovery.image" -}}
  40. {{ include "common.images.image" (dict "imageRoot" .Values.externalAccess.autoDiscovery.image "global" .Values.global) }}
  41. {{- end -}}
  42. {{/*
  43. Return the proper image name (for the init container volume-permissions image)
  44. */}}
  45. {{- define "kafka.volumePermissions.image" -}}
  46. {{ include "common.images.image" (dict "imageRoot" .Values.volumePermissions.image "global" .Values.global) }}
  47. {{- end -}}
  48. {{/*
  49. Create a default fully qualified Kafka exporter name.
  50. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  51. */}}
  52. {{- define "kafka.metrics.kafka.fullname" -}}
  53. {{- printf "%s-exporter" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
  54. {{- end -}}
  55. {{/*
  56. Create the name of the service account to use for Kafka exporter pods
  57. */}}
  58. {{- define "kafka.metrics.kafka.serviceAccountName" -}}
  59. {{- if .Values.metrics.kafka.serviceAccount.create -}}
  60. {{ default (include "kafka.metrics.kafka.fullname" .) .Values.metrics.kafka.serviceAccount.name }}
  61. {{- else -}}
  62. {{ default "default" .Values.metrics.kafka.serviceAccount.name }}
  63. {{- end -}}
  64. {{- end -}}
  65. {{/*
  66. Return the proper Kafka exporter image name
  67. */}}
  68. {{- define "kafka.metrics.kafka.image" -}}
  69. {{ include "common.images.image" (dict "imageRoot" .Values.metrics.kafka.image "global" .Values.global) }}
  70. {{- end -}}
  71. {{/*
  72. Return the proper JMX exporter image name
  73. */}}
  74. {{- define "kafka.metrics.jmx.image" -}}
  75. {{ include "common.images.image" (dict "imageRoot" .Values.metrics.jmx.image "global" .Values.global) }}
  76. {{- end -}}
  77. {{/*
  78. Return the proper Docker Image Registry Secret Names
  79. */}}
  80. {{- define "kafka.imagePullSecrets" -}}
  81. {{ include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.externalAccess.autoDiscovery.image .Values.volumePermissions.image .Values.metrics.kafka.image .Values.metrics.jmx.image) "global" .Values.global) }}
  82. {{- end -}}
  83. {{/*
  84. Return the proper Storage Class
  85. */}}
  86. {{- define "kafka.storageClass" -}}
  87. {{/*
  88. Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
  89. but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic.
  90. */}}
  91. {{- if .Values.global -}}
  92. {{- if .Values.global.storageClass -}}
  93. {{- if (eq "-" .Values.global.storageClass) -}}
  94. {{- printf "storageClassName: \"\"" -}}
  95. {{- else }}
  96. {{- printf "storageClassName: %s" .Values.global.storageClass -}}
  97. {{- end -}}
  98. {{- else -}}
  99. {{- if .Values.persistence.storageClass -}}
  100. {{- if (eq "-" .Values.persistence.storageClass) -}}
  101. {{- printf "storageClassName: \"\"" -}}
  102. {{- else }}
  103. {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
  104. {{- end -}}
  105. {{- end -}}
  106. {{- end -}}
  107. {{- else -}}
  108. {{- if .Values.persistence.storageClass -}}
  109. {{- if (eq "-" .Values.persistence.storageClass) -}}
  110. {{- printf "storageClassName: \"\"" -}}
  111. {{- else }}
  112. {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
  113. {{- end -}}
  114. {{- end -}}
  115. {{- end -}}
  116. {{- end -}}
  117. {{/*
  118. Return true if authentication via SASL should be configured for client communications
  119. */}}
  120. {{- define "kafka.client.saslAuthentication" -}}
  121. {{- $saslProtocols := list "sasl" "sasl_tls" -}}
  122. {{- if has .Values.auth.clientProtocol $saslProtocols -}}
  123. {{- true -}}
  124. {{- end -}}
  125. {{- end -}}
  126. {{/*
  127. Return true if authentication via SASL should be configured for inter-broker communications
  128. */}}
  129. {{- define "kafka.interBroker.saslAuthentication" -}}
  130. {{- $saslProtocols := list "sasl" "sasl_tls" -}}
  131. {{- if has .Values.auth.interBrokerProtocol $saslProtocols -}}
  132. {{- true -}}
  133. {{- end -}}
  134. {{- end -}}
  135. {{/*
  136. Return true if encryption via TLS for client connections should be configured
  137. */}}
  138. {{- define "kafka.client.tlsEncryption" -}}
  139. {{- $tlsProtocols := list "tls" "mtls" "sasl_tls" -}}
  140. {{- if (has .Values.auth.clientProtocol $tlsProtocols) -}}
  141. {{- true -}}
  142. {{- end -}}
  143. {{- end -}}
  144. {{/*
  145. Return the configured value for the external client protocol, defaults to the same value as clientProtocol
  146. */}}
  147. {{- define "kafka.externalClientProtocol" -}}
  148. {{- coalesce .Values.auth.externalClientProtocol .Values.auth.clientProtocol -}}
  149. {{- end -}}
  150. {{/*
  151. Return true if encryption via TLS for external client connections should be configured
  152. */}}
  153. {{- define "kafka.externalClient.tlsEncryption" -}}
  154. {{- $tlsProtocols := list "tls" "mtls" "sasl_tls" -}}
  155. {{- if (has (include "kafka.externalClientProtocol" . ) $tlsProtocols) -}}
  156. {{- true -}}
  157. {{- end -}}
  158. {{- end -}}
  159. {{/*
  160. Return true if encryption via TLS for inter broker communication connections should be configured
  161. */}}
  162. {{- define "kafka.interBroker.tlsEncryption" -}}
  163. {{- $tlsProtocols := list "tls" "mtls" "sasl_tls" -}}
  164. {{- if (has .Values.auth.interBrokerProtocol $tlsProtocols) -}}
  165. {{- true -}}
  166. {{- end -}}
  167. {{- end -}}
  168. {{/*
  169. Return true if encryption via TLS should be configured
  170. */}}
  171. {{- define "kafka.tlsEncryption" -}}
  172. {{- if or (include "kafka.client.tlsEncryption" .) (include "kafka.interBroker.tlsEncryption" .) (include "kafka.externalClient.tlsEncryption" .) -}}
  173. {{- true -}}
  174. {{- end -}}
  175. {{- end -}}
  176. {{/*
  177. Return the type of listener
  178. Usage:
  179. {{ include "kafka.listenerType" ( dict "protocol" .Values.path.to.the.Value ) }}
  180. */}}
  181. {{- define "kafka.listenerType" -}}
  182. {{- if eq .protocol "plaintext" -}}
  183. PLAINTEXT
  184. {{- else if or (eq .protocol "tls") (eq .protocol "mtls") -}}
  185. SSL
  186. {{- else if eq .protocol "sasl_tls" -}}
  187. SASL_SSL
  188. {{- else if eq .protocol "sasl" -}}
  189. SASL_PLAINTEXT
  190. {{- end -}}
  191. {{- end -}}
  192. {{/*
  193. Return the protocol used with zookeeper
  194. */}}
  195. {{- define "kafka.zookeeper.protocol" -}}
  196. {{- if and .Values.auth.zookeeper.tls.enabled .Values.zookeeper.auth.client.enabled .Values.auth.sasl.jaas.zookeeperUser -}}
  197. SASL_SSL
  198. {{- else if and .Values.auth.zookeeper.tls.enabled -}}
  199. SSL
  200. {{- else if and .Values.zookeeper.auth.client.enabled .Values.auth.sasl.jaas.zookeeperUser -}}
  201. SASL
  202. {{- else -}}
  203. PLAINTEXT
  204. {{- end -}}
  205. {{- end -}}
  206. {{/*
  207. Return the Kafka JAAS credentials secret
  208. */}}
  209. {{- define "kafka.jaasSecretName" -}}
  210. {{- $secretName := .Values.auth.sasl.jaas.existingSecret -}}
  211. {{- if $secretName -}}
  212. {{- printf "%s" (tpl $secretName $) -}}
  213. {{- else -}}
  214. {{- printf "%s-jaas" (include "common.names.fullname" .) -}}
  215. {{- end -}}
  216. {{- end -}}
  217. {{/*
  218. Return true if a JAAS credentials secret object should be created
  219. */}}
  220. {{- define "kafka.createJaasSecret" -}}
  221. {{- $secretName := .Values.auth.sasl.jaas.existingSecret -}}
  222. {{- if and (or (include "kafka.client.saslAuthentication" .) (include "kafka.interBroker.saslAuthentication" .) (and .Values.zookeeper.auth.client.enabled .Values.auth.sasl.jaas.zookeeperUser)) (empty $secretName) -}}
  223. {{- true -}}
  224. {{- end -}}
  225. {{- end -}}
  226. {{/*
  227. Return true if a TLS credentials secret object should be created
  228. */}}
  229. {{- define "kafka.createTlsSecret" -}}
  230. {{- if and (include "kafka.tlsEncryption" .) (empty .Values.auth.tls.existingSecrets) (eq .Values.auth.tls.type "pem") .Values.auth.tls.autoGenerated }}
  231. {{- true -}}
  232. {{- end -}}
  233. {{- end -}}
  234. {{/*
  235. Return the Kafka configuration configmap
  236. */}}
  237. {{- define "kafka.configmapName" -}}
  238. {{- if .Values.existingConfigmap -}}
  239. {{- printf "%s" (tpl .Values.existingConfigmap $) -}}
  240. {{- else -}}
  241. {{- printf "%s-configuration" (include "common.names.fullname" .) -}}
  242. {{- end -}}
  243. {{- end -}}
  244. {{/*
  245. Returns the secret name for the Kafka Provisioning client
  246. */}}
  247. {{- define "kafka.client.passwordsSecretName" -}}
  248. {{- if .Values.provisioning.auth.tls.passwordsSecret -}}
  249. {{- printf "%s" (tpl .Values.provisioning.auth.tls.passwordsSecret $) -}}
  250. {{- else -}}
  251. {{- printf "%s-client-secret" (include "common.names.fullname" .) -}}
  252. {{- end -}}
  253. {{- end -}}
  254. {{/*
  255. Create the name of the service account to use for the Kafka Provisioning client
  256. */}}
  257. {{- define "kafka.provisioning.serviceAccountName" -}}
  258. {{- if .Values.provisioning.serviceAccount.create -}}
  259. {{ default (include "common.names.fullname" .) .Values.provisioning.serviceAccount.name }}
  260. {{- else -}}
  261. {{ default "default" .Values.provisioning.serviceAccount.name }}
  262. {{- end -}}
  263. {{- end -}}
  264. {{/*
  265. Return true if a configmap object should be created
  266. */}}
  267. {{- define "kafka.createConfigmap" -}}
  268. {{- if and .Values.config (not .Values.existingConfigmap) }}
  269. {{- true -}}
  270. {{- end -}}
  271. {{- end -}}
  272. {{/*
  273. Return the Kafka log4j ConfigMap name.
  274. */}}
  275. {{- define "kafka.log4j.configMapName" -}}
  276. {{- if .Values.existingLog4jConfigMap -}}
  277. {{- printf "%s" (tpl .Values.existingLog4jConfigMap $) -}}
  278. {{- else -}}
  279. {{- printf "%s-log4j-configuration" (include "common.names.fullname" .) -}}
  280. {{- end -}}
  281. {{- end -}}
  282. {{/*
  283. Return true if a log4j ConfigMap object should be created.
  284. */}}
  285. {{- define "kafka.log4j.createConfigMap" -}}
  286. {{- if and .Values.log4j (not .Values.existingLog4jConfigMap) }}
  287. {{- true -}}
  288. {{- end -}}
  289. {{- end -}}
  290. {{/*
  291. Return the SASL mechanism to use for the Kafka exporter to access Kafka
  292. The exporter uses a different nomenclature so we need to do this hack
  293. */}}
  294. {{- define "kafka.metrics.kafka.saslMechanism" -}}
  295. {{- $saslMechanisms := .Values.auth.sasl.mechanisms }}
  296. {{- if contains "scram-sha-512" $saslMechanisms }}
  297. {{- print "scram-sha512" -}}
  298. {{- else if contains "scram-sha-256" $saslMechanisms }}
  299. {{- print "scram-sha256" -}}
  300. {{- else -}}
  301. {{- print "plain" -}}
  302. {{- end -}}
  303. {{- end -}}
  304. {{/*
  305. Return the Kafka configuration configmap
  306. */}}
  307. {{- define "kafka.metrics.jmx.configmapName" -}}
  308. {{- if .Values.metrics.jmx.existingConfigmap -}}
  309. {{- printf "%s" (tpl .Values.metrics.jmx.existingConfigmap $) -}}
  310. {{- else -}}
  311. {{- printf "%s-jmx-configuration" (include "common.names.fullname" .) -}}
  312. {{- end -}}
  313. {{- end -}}
  314. {{/*
  315. Return true if a configmap object should be created
  316. */}}
  317. {{- define "kafka.metrics.jmx.createConfigmap" -}}
  318. {{- if and .Values.metrics.jmx.enabled .Values.metrics.jmx.config (not .Values.metrics.jmx.existingConfigmap) }}
  319. {{- true -}}
  320. {{- end -}}
  321. {{- end -}}
  322. {{/*
  323. Check if there are rolling tags in the images
  324. */}}
  325. {{- define "kafka.checkRollingTags" -}}
  326. {{- include "common.warnings.rollingTag" .Values.image }}
  327. {{- include "common.warnings.rollingTag" .Values.externalAccess.autoDiscovery.image }}
  328. {{- include "common.warnings.rollingTag" .Values.metrics.kafka.image }}
  329. {{- include "common.warnings.rollingTag" .Values.metrics.jmx.image }}
  330. {{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
  331. {{- end -}}
  332. {{/*
  333. Compile all warnings into a single message, and call fail.
  334. */}}
  335. {{- define "kafka.validateValues" -}}
  336. {{- $messages := list -}}
  337. {{- $messages := append $messages (include "kafka.validateValues.authProtocols" .) -}}
  338. {{- $messages := append $messages (include "kafka.validateValues.nodePortListLength" .) -}}
  339. {{- $messages := append $messages (include "kafka.validateValues.domainSpecified" .) -}}
  340. {{- $messages := append $messages (include "kafka.validateValues.externalAccessServiceType" .) -}}
  341. {{- $messages := append $messages (include "kafka.validateValues.externalAccessAutoDiscoveryRBAC" .) -}}
  342. {{- $messages := append $messages (include "kafka.validateValues.externalAccessAutoDiscoveryIPsOrNames" .) -}}
  343. {{- $messages := append $messages (include "kafka.validateValues.externalAccessServiceList" (dict "element" "loadBalancerIPs" "context" .)) -}}
  344. {{- $messages := append $messages (include "kafka.validateValues.externalAccessServiceList" (dict "element" "loadBalancerNames" "context" .)) -}}
  345. {{- $messages := append $messages (include "kafka.validateValues.externalAccessServiceList" (dict "element" "loadBalancerAnnotations" "context" . )) -}}
  346. {{- $messages := append $messages (include "kafka.validateValues.saslMechanisms" .) -}}
  347. {{- $messages := append $messages (include "kafka.validateValues.tlsSecrets" .) -}}
  348. {{- $messages := append $messages (include "kafka.validateValues.tlsSecrets.length" .) -}}
  349. {{- $messages := append $messages (include "kafka.validateValues.tlsPasswords" .) -}}
  350. {{- $messages := without $messages "" -}}
  351. {{- $message := join "\n" $messages -}}
  352. {{- if $message -}}
  353. {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
  354. {{- end -}}
  355. {{- end -}}
  356. {{/* Validate values of Kafka - Authentication protocols for Kafka */}}
  357. {{- define "kafka.validateValues.authProtocols" -}}
  358. {{- $authProtocols := list "plaintext" "tls" "mtls" "sasl" "sasl_tls" -}}
  359. {{- if or (not (has .Values.auth.clientProtocol $authProtocols)) (not (has .Values.auth.interBrokerProtocol $authProtocols)) (not (has (include "kafka.externalClientProtocol" . ) $authProtocols)) -}}
  360. kafka: auth.clientProtocol auth.externalClientProtocol auth.interBrokerProtocol
  361. Available authentication protocols are "plaintext", "tls", "mtls", "sasl" and "sasl_tls"
  362. {{- end -}}
  363. {{- end -}}
  364. {{/* Validate values of Kafka - number of replicas must be the same as NodePort list */}}
  365. {{- define "kafka.validateValues.nodePortListLength" -}}
  366. {{- $replicaCount := int .Values.replicaCount }}
  367. {{- $nodePortListLength := len .Values.externalAccess.service.nodePorts }}
  368. {{- if and .Values.externalAccess.enabled (not .Values.externalAccess.autoDiscovery.enabled) (not (eq $replicaCount $nodePortListLength )) (eq .Values.externalAccess.service.type "NodePort") -}}
  369. kafka: .Values.externalAccess.service.nodePorts
  370. Number of replicas and nodePort array length must be the same. Currently: replicaCount = {{ $replicaCount }} and nodePorts = {{ $nodePortListLength }}
  371. {{- end -}}
  372. {{- end -}}
  373. {{/* Validate values of Kafka - domain must be defined if external service type ClusterIP */}}
  374. {{- define "kafka.validateValues.domainSpecified" -}}
  375. {{- if and (eq .Values.externalAccess.service.type "ClusterIP") (eq .Values.externalAccess.service.domain "") -}}
  376. kafka: .Values.externalAccess.service.domain
  377. Domain must be specified if service type ClusterIP is set for external service
  378. {{- end -}}
  379. {{- end -}}
  380. {{/* Validate values of Kafka - service type for external access */}}
  381. {{- define "kafka.validateValues.externalAccessServiceType" -}}
  382. {{- if and (not (eq .Values.externalAccess.service.type "NodePort")) (not (eq .Values.externalAccess.service.type "LoadBalancer")) (not (eq .Values.externalAccess.service.type "ClusterIP")) -}}
  383. kafka: externalAccess.service.type
  384. Available service type for external access are NodePort, LoadBalancer or ClusterIP.
  385. {{- end -}}
  386. {{- end -}}
  387. {{/* Validate values of Kafka - RBAC should be enabled when autoDiscovery is enabled */}}
  388. {{- define "kafka.validateValues.externalAccessAutoDiscoveryRBAC" -}}
  389. {{- if and .Values.externalAccess.enabled .Values.externalAccess.autoDiscovery.enabled (not .Values.rbac.create ) }}
  390. kafka: rbac.create
  391. By specifying "externalAccess.enabled=true" and "externalAccess.autoDiscovery.enabled=true"
  392. an initContainer will be used to auto-detect the external IPs/ports by querying the
  393. K8s API. Please note this initContainer requires specific RBAC resources. You can create them
  394. by specifying "--set rbac.create=true".
  395. {{- end -}}
  396. {{- end -}}
  397. {{/* Validate values of Kafka - LoadBalancerIPs or LoadBalancerNames should be set when autoDiscovery is disabled */}}
  398. {{- define "kafka.validateValues.externalAccessAutoDiscoveryIPsOrNames" -}}
  399. {{- $loadBalancerNameListLength := len .Values.externalAccess.service.loadBalancerNames -}}
  400. {{- $loadBalancerIPListLength := len .Values.externalAccess.service.loadBalancerIPs -}}
  401. {{- if and .Values.externalAccess.enabled (eq .Values.externalAccess.service.type "LoadBalancer") (not .Values.externalAccess.autoDiscovery.enabled) (eq $loadBalancerNameListLength 0) (eq $loadBalancerIPListLength 0) }}
  402. kafka: externalAccess.service.loadBalancerNames or externalAccess.service.loadBalancerIPs
  403. By specifying "externalAccess.enabled=true", "externalAccess.autoDiscovery.enabled=false" and
  404. "externalAccess.service.type=LoadBalancer" at least one of externalAccess.service.loadBalancerNames
  405. or externalAccess.service.loadBalancerIPs must be set and the length of those arrays must be equal
  406. to the number of replicas.
  407. {{- end -}}
  408. {{- end -}}
  409. {{/* Validate values of Kafka - number of replicas must be the same as loadBalancerIPs list */}}
  410. {{- define "kafka.validateValues.externalAccessServiceList" -}}
  411. {{- $replicaCount := int .context.Values.replicaCount }}
  412. {{- $listLength := len (get .context.Values.externalAccess.service .element) -}}
  413. {{- if and .context.Values.externalAccess.enabled (not .context.Values.externalAccess.autoDiscovery.enabled) (eq .context.Values.externalAccess.service.type "LoadBalancer") (gt $listLength 0) (not (eq $replicaCount $listLength)) }}
  414. kafka: externalAccess.service.{{ .element }}
  415. Number of replicas and {{ .element }} array length must be the same. Currently: replicaCount = {{ $replicaCount }} and {{ .element }} = {{ $listLength }}
  416. {{- end -}}
  417. {{- end -}}
  418. {{/* Validate values of Kafka - SASL mechanisms must be provided when using SASL */}}
  419. {{- define "kafka.validateValues.saslMechanisms" -}}
  420. {{- if and (or (.Values.auth.clientProtocol | regexFind "sasl") (.Values.auth.interBrokerProtocol | regexFind "sasl") (and .Values.zookeeper.auth.client.enabled .Values.auth.sasl.jaas.zookeeperUser)) (not .Values.auth.sasl.mechanisms) }}
  421. kafka: auth.sasl.mechanisms
  422. The SASL mechanisms are required when either auth.clientProtocol or auth.interBrokerProtocol use SASL or Zookeeper user is provided.
  423. {{- end }}
  424. {{- if not (contains .Values.auth.sasl.interBrokerMechanism .Values.auth.sasl.mechanisms) }}
  425. kafka: auth.sasl.mechanisms
  426. auth.sasl.interBrokerMechanism must be provided and it should be one of the specified mechanisms at auth.saslMechanisms
  427. {{- end -}}
  428. {{- end -}}
  429. {{/* Validate values of Kafka - Secrets containing TLS certs must be provided when TLS authentication is enabled */}}
  430. {{- define "kafka.validateValues.tlsSecrets" -}}
  431. {{- if and (include "kafka.tlsEncryption" .) (eq .Values.auth.tls.type "jks") (empty .Values.auth.tls.existingSecrets) }}
  432. kafka: auth.tls.existingSecrets
  433. A secret containing the Kafka JKS keystores and truststore is required
  434. when TLS encryption in enabled and TLS format is "JKS"
  435. {{- else if and (include "kafka.tlsEncryption" .) (eq .Values.auth.tls.type "pem") (empty .Values.auth.tls.existingSecrets) (not .Values.auth.tls.autoGenerated) }}
  436. kafka: auth.tls.existingSecrets
  437. A secret containing the Kafka TLS certificates and keys is required
  438. when TLS encryption in enabled and TLS format is "PEM"
  439. {{- end -}}
  440. {{- end -}}
  441. {{/* Validate values of Kafka - The number of secrets containing TLS certs should be equal to the number of replicas */}}
  442. {{- define "kafka.validateValues.tlsSecrets.length" -}}
  443. {{- $replicaCount := int .Values.replicaCount }}
  444. {{- if and (include "kafka.tlsEncryption" .) (not (empty .Values.auth.tls.existingSecrets)) }}
  445. {{- $existingSecretsLength := len .Values.auth.tls.existingSecrets }}
  446. {{- if ne $replicaCount $existingSecretsLength }}
  447. kafka: .Values.auth.tls.existingSecrets
  448. Number of replicas and existingSecrets array length must be the same. Currently: replicaCount = {{ $replicaCount }} and existingSecrets = {{ $existingSecretsLength }}
  449. {{- end -}}
  450. {{- end -}}
  451. {{- end -}}
  452. {{/* Validate values of Kafka provisioning - keyPasswordSecretKey, keystorePasswordSecretKey or truststorePasswordSecretKey must not be used without passwordsSecret */}}
  453. {{- define "kafka.validateValues.tlsPasswords" -}}
  454. {{- if and (include "kafka.client.tlsEncryption" .) (not .Values.auth.tls.passwordsSecret) }}
  455. {{- if or .Values.auth.tls.keyPasswordSecretKey .Values.auth.tls.keystorePasswordSecretKey .Values.auth.tls.truststorePasswordSecretKey }}
  456. kafka: auth.tls.keyPasswordSecretKey,auth.tls.keystorePasswordSecretKey,auth.tls.truststorePasswordSecretKey
  457. auth.tls.keyPasswordSecretKey,auth.tls.keystorePasswordSecretKey,auth.tls.truststorePasswordSecretKey
  458. must not be used without passwordsSecret setted.
  459. {{- end -}}
  460. {{- end -}}
  461. {{- end -}}