_helpers.tpl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. {{/*
  2. Copyright Broadcom, Inc. All Rights Reserved.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Return the proper ZooKeeper image name
  8. */}}
  9. {{- define "zookeeper.image" -}}
  10. {{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
  11. {{- end -}}
  12. {{/*
  13. Return the proper image name (for the init container volume-permissions image)
  14. */}}
  15. {{- define "zookeeper.volumePermissions.image" -}}
  16. {{ include "common.images.image" (dict "imageRoot" .Values.volumePermissions.image "global" .Values.global) }}
  17. {{- end -}}
  18. {{/*
  19. Return the proper Docker Image Registry Secret Names
  20. */}}
  21. {{- define "zookeeper.imagePullSecrets" -}}
  22. {{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.volumePermissions.image) "global" .Values.global) -}}
  23. {{- end -}}
  24. {{/*
  25. Check if there are rolling tags in the images
  26. */}}
  27. {{- define "zookeeper.checkRollingTags" -}}
  28. {{- include "common.warnings.rollingTag" .Values.image }}
  29. {{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
  30. {{- end -}}
  31. {{/*
  32. Return ZooKeeper Namespace to use
  33. */}}
  34. {{- define "zookeeper.namespace" -}}
  35. {{- if .Values.namespaceOverride -}}
  36. {{- .Values.namespaceOverride -}}
  37. {{- else -}}
  38. {{- .Release.Namespace -}}
  39. {{- end -}}
  40. {{- end -}}
  41. {{/*
  42. Create the name of the service account to use
  43. */}}
  44. {{- define "zookeeper.serviceAccountName" -}}
  45. {{- if .Values.serviceAccount.create -}}
  46. {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
  47. {{- else -}}
  48. {{ default "default" .Values.serviceAccount.name }}
  49. {{- end -}}
  50. {{- end -}}
  51. {{/*
  52. Return the ZooKeeper client-server authentication credentials secret
  53. */}}
  54. {{- define "zookeeper.client.secretName" -}}
  55. {{- if .Values.auth.client.existingSecret -}}
  56. {{- printf "%s" (tpl .Values.auth.client.existingSecret $) -}}
  57. {{- else -}}
  58. {{- printf "%s-client-auth" (include "common.names.fullname" .) -}}
  59. {{- end -}}
  60. {{- end -}}
  61. {{/*
  62. Return the ZooKeeper server-server authentication credentials secret
  63. */}}
  64. {{- define "zookeeper.quorum.secretName" -}}
  65. {{- if .Values.auth.quorum.existingSecret -}}
  66. {{- printf "%s" (tpl .Values.auth.quorum.existingSecret $) -}}
  67. {{- else -}}
  68. {{- printf "%s-quorum-auth" (include "common.names.fullname" .) -}}
  69. {{- end -}}
  70. {{- end -}}
  71. {{/*
  72. Return true if a ZooKeeper client-server authentication credentials secret object should be created
  73. */}}
  74. {{- define "zookeeper.client.createSecret" -}}
  75. {{- if and .Values.auth.client.enabled (empty .Values.auth.client.existingSecret) -}}
  76. {{- true -}}
  77. {{- end -}}
  78. {{- end -}}
  79. {{/*
  80. Return true if a ZooKeeper server-server authentication credentials secret object should be created
  81. */}}
  82. {{- define "zookeeper.quorum.createSecret" -}}
  83. {{- if and .Values.auth.quorum.enabled (empty .Values.auth.quorum.existingSecret) -}}
  84. {{- true -}}
  85. {{- end -}}
  86. {{- end -}}
  87. {{/*
  88. Return the ZooKeeper configuration ConfigMap name
  89. */}}
  90. {{- define "zookeeper.configmapName" -}}
  91. {{- if .Values.existingConfigmap -}}
  92. {{- printf "%s" (tpl .Values.existingConfigmap $) -}}
  93. {{- else -}}
  94. {{- printf "%s" (include "common.names.fullname" .) -}}
  95. {{- end -}}
  96. {{- end -}}
  97. {{/*
  98. Return true if a ConfigMap object should be created for ZooKeeper configuration
  99. */}}
  100. {{- define "zookeeper.createConfigmap" -}}
  101. {{- if and .Values.configuration (not .Values.existingConfigmap) }}
  102. {{- true -}}
  103. {{- end -}}
  104. {{- end -}}
  105. {{/*
  106. Return true if a TLS secret should be created for ZooKeeper quorum
  107. */}}
  108. {{- define "zookeeper.quorum.createTlsSecret" -}}
  109. {{- if and .Values.tls.quorum.enabled .Values.tls.quorum.autoGenerated (not .Values.tls.quorum.existingSecret) }}
  110. {{- true -}}
  111. {{- end -}}
  112. {{- end -}}
  113. {{/*
  114. Return the secret containing ZooKeeper quorum TLS certificates
  115. */}}
  116. {{- define "zookeeper.quorum.tlsSecretName" -}}
  117. {{- $secretName := .Values.tls.quorum.existingSecret -}}
  118. {{- if $secretName -}}
  119. {{- printf "%s" (tpl $secretName $) -}}
  120. {{- else -}}
  121. {{- printf "%s-quorum-crt" (include "common.names.fullname" .) -}}
  122. {{- end -}}
  123. {{- end -}}
  124. {{/*
  125. Return true if a secret containing the Keystore and Truststore password should be created for ZooKeeper quorum
  126. */}}
  127. {{- define "zookeeper.quorum.createTlsPasswordsSecret" -}}
  128. {{- if and .Values.tls.quorum.enabled (not .Values.tls.quorum.passwordsSecretName) }}
  129. {{- true -}}
  130. {{- end -}}
  131. {{- end -}}
  132. {{/*
  133. Return the name of the secret containing the Keystore and Truststore password
  134. */}}
  135. {{- define "zookeeper.quorum.tlsPasswordsSecret" -}}
  136. {{- $secretName := .Values.tls.quorum.passwordsSecretName -}}
  137. {{- if $secretName -}}
  138. {{- printf "%s" (tpl $secretName $) -}}
  139. {{- else -}}
  140. {{- printf "%s-quorum-tls-pass" (include "common.names.fullname" .) -}}
  141. {{- end -}}
  142. {{- end -}}
  143. {{/*
  144. Return true if a TLS secret should be created for ZooKeeper client
  145. */}}
  146. {{- define "zookeeper.client.createTlsSecret" -}}
  147. {{- if and .Values.tls.client.enabled .Values.tls.client.autoGenerated (not .Values.tls.client.existingSecret) }}
  148. {{- true -}}
  149. {{- end -}}
  150. {{- end -}}
  151. {{/*
  152. Return the secret containing ZooKeeper client TLS certificates
  153. */}}
  154. {{- define "zookeeper.client.tlsSecretName" -}}
  155. {{- $secretName := .Values.tls.client.existingSecret -}}
  156. {{- if $secretName -}}
  157. {{- printf "%s" (tpl $secretName $) -}}
  158. {{- else -}}
  159. {{- printf "%s-client-crt" (include "common.names.fullname" .) -}}
  160. {{- end -}}
  161. {{- end -}}
  162. {{/*
  163. Get the quorum keystore key to be retrieved from tls.quorum.existingSecret.
  164. */}}
  165. {{- define "zookeeper.quorum.tlsKeystoreKey" -}}
  166. {{- if and .Values.tls.quorum.existingSecret .Values.tls.quorum.existingSecretKeystoreKey -}}
  167. {{- printf "%s" .Values.tls.quorum.existingSecretKeystoreKey -}}
  168. {{- else -}}
  169. {{- printf "zookeeper.keystore.jks" -}}
  170. {{- end -}}
  171. {{- end -}}
  172. {{/*
  173. Get the quorum truststore key to be retrieved from tls.quorum.existingSecret.
  174. */}}
  175. {{- define "zookeeper.quorum.tlsTruststoreKey" -}}
  176. {{- if and .Values.tls.quorum.existingSecret .Values.tls.quorum.existingSecretTruststoreKey -}}
  177. {{- printf "%s" .Values.tls.quorum.existingSecretTruststoreKey -}}
  178. {{- else -}}
  179. {{- printf "zookeeper.truststore.jks" -}}
  180. {{- end -}}
  181. {{- end -}}
  182. {{/*
  183. Get the client keystore key to be retrieved from tls.client.existingSecret.
  184. */}}
  185. {{- define "zookeeper.client.tlsKeystoreKey" -}}
  186. {{- if and .Values.tls.client.existingSecret .Values.tls.client.existingSecretKeystoreKey -}}
  187. {{- printf "%s" .Values.tls.client.existingSecretKeystoreKey -}}
  188. {{- else -}}
  189. {{- printf "zookeeper.keystore.jks" -}}
  190. {{- end -}}
  191. {{- end -}}
  192. {{/*
  193. Get the client truststore key to be retrieved from tls.client.existingSecret.
  194. */}}
  195. {{- define "zookeeper.client.tlsTruststoreKey" -}}
  196. {{- if and .Values.tls.client.existingSecret .Values.tls.client.existingSecretTruststoreKey -}}
  197. {{- printf "%s" .Values.tls.client.existingSecretTruststoreKey -}}
  198. {{- else -}}
  199. {{- printf "zookeeper.truststore.jks" -}}
  200. {{- end -}}
  201. {{- end -}}
  202. {{/*
  203. Return true if a secret containing the Keystore and Truststore password should be created for ZooKeeper client
  204. */}}
  205. {{- define "zookeeper.client.createTlsPasswordsSecret" -}}
  206. {{- if and .Values.tls.client.enabled (not .Values.tls.client.passwordsSecretName) }}
  207. {{- true -}}
  208. {{- end -}}
  209. {{- end -}}
  210. {{/*
  211. Return the name of the secret containing the Keystore and Truststore password
  212. */}}
  213. {{- define "zookeeper.client.tlsPasswordsSecret" -}}
  214. {{- $secretName := .Values.tls.client.passwordsSecretName -}}
  215. {{- if $secretName -}}
  216. {{- printf "%s" (tpl $secretName $) -}}
  217. {{- else -}}
  218. {{- printf "%s-client-tls-pass" (include "common.names.fullname" .) -}}
  219. {{- end -}}
  220. {{- end -}}
  221. {{/*
  222. Get the quorum keystore password key to be retrieved from tls.quorum.passwordSecretName.
  223. */}}
  224. {{- define "zookeeper.quorum.tlsPasswordKeystoreKey" -}}
  225. {{- if and .Values.tls.quorum.passwordsSecretName .Values.tls.quorum.passwordsSecretKeystoreKey -}}
  226. {{- printf "%s" .Values.tls.quorum.passwordsSecretKeystoreKey -}}
  227. {{- else -}}
  228. {{- printf "keystore-password" -}}
  229. {{- end -}}
  230. {{- end -}}
  231. {{/*
  232. Get the quorum truststore password key to be retrieved from tls.quorum.passwordSecretName.
  233. */}}
  234. {{- define "zookeeper.quorum.tlsPasswordTruststoreKey" -}}
  235. {{- if and .Values.tls.quorum.passwordsSecretName .Values.tls.quorum.passwordsSecretTruststoreKey -}}
  236. {{- printf "%s" .Values.tls.quorum.passwordsSecretTruststoreKey -}}
  237. {{- else -}}
  238. {{- printf "truststore-password" -}}
  239. {{- end -}}
  240. {{- end -}}
  241. {{/*
  242. Get the client keystore password key to be retrieved from tls.client.passwordSecretName.
  243. */}}
  244. {{- define "zookeeper.client.tlsPasswordKeystoreKey" -}}
  245. {{- if and .Values.tls.client.passwordsSecretName .Values.tls.client.passwordsSecretKeystoreKey -}}
  246. {{- printf "%s" .Values.tls.client.passwordsSecretKeystoreKey -}}
  247. {{- else -}}
  248. {{- printf "keystore-password" -}}
  249. {{- end -}}
  250. {{- end -}}
  251. {{/*
  252. Get the client truststore password key to be retrieved from tls.client.passwordSecretName.
  253. */}}
  254. {{- define "zookeeper.client.tlsPasswordTruststoreKey" -}}
  255. {{- if and .Values.tls.client.passwordsSecretName .Values.tls.client.passwordsSecretTruststoreKey -}}
  256. {{- printf "%s" .Values.tls.client.passwordsSecretTruststoreKey -}}
  257. {{- else -}}
  258. {{- printf "truststore-password" -}}
  259. {{- end -}}
  260. {{- end -}}
  261. {{/*
  262. Compile all warnings into a single message.
  263. */}}
  264. {{- define "zookeeper.validateValues" -}}
  265. {{- $messages := list -}}
  266. {{- $messages := append $messages (include "zookeeper.validateValues.client.auth" .) -}}
  267. {{- $messages := append $messages (include "zookeeper.validateValues.quorum.auth" .) -}}
  268. {{- $messages := append $messages (include "zookeeper.validateValues.client.tls" .) -}}
  269. {{- $messages := append $messages (include "zookeeper.validateValues.quorum.tls" .) -}}
  270. {{- $messages := without $messages "" -}}
  271. {{- $message := join "\n" $messages -}}
  272. {{- if $message -}}
  273. {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
  274. {{- end -}}
  275. {{- end -}}
  276. {{/*
  277. Validate values of ZooKeeper - Authentication enabled
  278. */}}
  279. {{- define "zookeeper.validateValues.client.auth" -}}
  280. {{- if and .Values.auth.client.enabled (not .Values.auth.client.existingSecret) (or (not .Values.auth.client.clientUser) (not .Values.auth.client.serverUsers)) }}
  281. zookeeper: auth.client.enabled
  282. In order to enable client-server authentication, you need to provide the list
  283. of users to be created and the user to use for clients authentication.
  284. {{- end -}}
  285. {{- end -}}
  286. {{/*
  287. Validate values of ZooKeeper - Authentication enabled
  288. */}}
  289. {{- define "zookeeper.validateValues.quorum.auth" -}}
  290. {{- if and .Values.auth.quorum.enabled (not .Values.auth.quorum.existingSecret) (or (not .Values.auth.quorum.learnerUser) (not .Values.auth.quorum.serverUsers)) }}
  291. zookeeper: auth.quorum.enabled
  292. In order to enable server-server authentication, you need to provide the list
  293. of users to be created and the user to use for quorum authentication.
  294. {{- end -}}
  295. {{- end -}}
  296. {{/*
  297. Validate values of ZooKeeper - Client TLS enabled
  298. */}}
  299. {{- define "zookeeper.validateValues.client.tls" -}}
  300. {{- if and .Values.tls.client.enabled (not .Values.tls.client.autoGenerated) (not .Values.tls.client.existingSecret) }}
  301. zookeeper: tls.client.enabled
  302. In order to enable Client TLS encryption, you also need to provide
  303. an existing secret containing the Keystore and Truststore or
  304. enable auto-generated certificates.
  305. {{- end -}}
  306. {{- end -}}
  307. {{/*
  308. Validate values of ZooKeeper - Quorum TLS enabled
  309. */}}
  310. {{- define "zookeeper.validateValues.quorum.tls" -}}
  311. {{- if and .Values.tls.quorum.enabled (not .Values.tls.quorum.autoGenerated) (not .Values.tls.quorum.existingSecret) }}
  312. zookeeper: tls.quorum.enabled
  313. In order to enable Quorum TLS, you also need to provide
  314. an existing secret containing the Keystore and Truststore or
  315. enable auto-generated certificates.
  316. {{- end -}}
  317. {{- end -}}