_helpers.tpl 12 KB

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