_helpers.tpl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. {{/* vim: set filetype=mustache: */}}
  2. {{- define "mysql.primary.fullname" -}}
  3. {{- if eq .Values.architecture "replication" }}
  4. {{- printf "%s-%s" (include "common.names.fullname" .) .Values.primary.name | trunc 63 | trimSuffix "-" -}}
  5. {{- else -}}
  6. {{- include "common.names.fullname" . -}}
  7. {{- end -}}
  8. {{- end -}}
  9. {{- define "mysql.secondary.fullname" -}}
  10. {{- printf "%s-%s" (include "common.names.fullname" .) .Values.secondary.name | trunc 63 | trimSuffix "-" -}}
  11. {{- end -}}
  12. {{/*
  13. Return the proper MySQL image name
  14. */}}
  15. {{- define "mysql.image" -}}
  16. {{- include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
  17. {{- end -}}
  18. {{/*
  19. Return the proper metrics image name
  20. */}}
  21. {{- define "mysql.metrics.image" -}}
  22. {{- include "common.images.image" (dict "imageRoot" .Values.metrics.image "global" .Values.global) }}
  23. {{- end -}}
  24. {{/*
  25. Return the proper image name (for the init container volume-permissions image)
  26. */}}
  27. {{- define "mysql.volumePermissions.image" -}}
  28. {{- include "common.images.image" (dict "imageRoot" .Values.volumePermissions.image "global" .Values.global) }}
  29. {{- end -}}
  30. {{/*
  31. Return the proper Docker Image Registry Secret Names
  32. */}}
  33. {{- define "mysql.imagePullSecrets" -}}
  34. {{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.metrics.image .Values.volumePermissions.image) "global" .Values.global) }}
  35. {{- end -}}
  36. {{/*
  37. Get the initialization scripts ConfigMap name.
  38. */}}
  39. {{- define "mysql.initdbScriptsCM" -}}
  40. {{- if .Values.initdbScriptsConfigMap -}}
  41. {{- printf "%s" (tpl .Values.initdbScriptsConfigMap $) -}}
  42. {{- else -}}
  43. {{- printf "%s-init-scripts" (include "mysql.primary.fullname" .) -}}
  44. {{- end -}}
  45. {{- end -}}
  46. {{/*
  47. Returns the proper service account name depending if an explicit service account name is set
  48. in the values file. If the name is not set it will default to either mysql.fullname if serviceAccount.create
  49. is true or default otherwise.
  50. */}}
  51. {{- define "mysql.serviceAccountName" -}}
  52. {{- if .Values.serviceAccount.create -}}
  53. {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
  54. {{- else -}}
  55. {{ default "default" .Values.serviceAccount.name }}
  56. {{- end -}}
  57. {{- end -}}
  58. {{/*
  59. Return the configmap with the MySQL Primary configuration
  60. */}}
  61. {{- define "mysql.primary.configmapName" -}}
  62. {{- if .Values.primary.existingConfigmap -}}
  63. {{- printf "%s" (tpl .Values.primary.existingConfigmap $) -}}
  64. {{- else -}}
  65. {{- printf "%s" (include "mysql.primary.fullname" .) -}}
  66. {{- end -}}
  67. {{- end -}}
  68. {{/*
  69. Return true if a configmap object should be created for MySQL Secondary
  70. */}}
  71. {{- define "mysql.primary.createConfigmap" -}}
  72. {{- if and .Values.primary.configuration (not .Values.primary.existingConfigmap) }}
  73. {{- true -}}
  74. {{- else -}}
  75. {{- end -}}
  76. {{- end -}}
  77. {{/*
  78. Return the configmap with the MySQL Primary configuration
  79. */}}
  80. {{- define "mysql.secondary.configmapName" -}}
  81. {{- if .Values.secondary.existingConfigmap -}}
  82. {{- printf "%s" (tpl .Values.secondary.existingConfigmap $) -}}
  83. {{- else -}}
  84. {{- printf "%s" (include "mysql.secondary.fullname" .) -}}
  85. {{- end -}}
  86. {{- end -}}
  87. {{/*
  88. Return true if a configmap object should be created for MySQL Secondary
  89. */}}
  90. {{- define "mysql.secondary.createConfigmap" -}}
  91. {{- if and (eq .Values.architecture "replication") .Values.secondary.configuration (not .Values.secondary.existingConfigmap) }}
  92. {{- true -}}
  93. {{- else -}}
  94. {{- end -}}
  95. {{- end -}}
  96. {{/*
  97. Return the secret with MySQL credentials
  98. */}}
  99. {{- define "mysql.secretName" -}}
  100. {{- if .Values.auth.existingSecret -}}
  101. {{- printf "%s" (tpl .Values.auth.existingSecret $) -}}
  102. {{- else -}}
  103. {{- printf "%s" (include "common.names.fullname" .) -}}
  104. {{- end -}}
  105. {{- end -}}
  106. {{/*
  107. Return true if a secret object should be created for MySQL
  108. */}}
  109. {{- define "mysql.createSecret" -}}
  110. {{- if and (not .Values.auth.existingSecret) (not .Values.auth.customPasswordFiles) }}
  111. {{- true -}}
  112. {{- end -}}
  113. {{- end -}}
  114. {{/*
  115. Returns the available value for certain key in an existing secret (if it exists),
  116. otherwise it generates a random value.
  117. */}}
  118. {{- define "getValueFromSecret" }}
  119. {{- $len := (default 16 .Length) | int -}}
  120. {{- $obj := (lookup "v1" "Secret" .Namespace .Name).data -}}
  121. {{- if $obj }}
  122. {{- index $obj .Key | b64dec -}}
  123. {{- else -}}
  124. {{- randAlphaNum $len -}}
  125. {{- end -}}
  126. {{- end }}
  127. {{/* Check if there are rolling tags in the images */}}
  128. {{- define "mysql.checkRollingTags" -}}
  129. {{- include "common.warnings.rollingTag" .Values.image }}
  130. {{- include "common.warnings.rollingTag" .Values.metrics.image }}
  131. {{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
  132. {{- end -}}
  133. {{/*
  134. Compile all warnings into a single message, and call fail.
  135. */}}
  136. {{- define "mysql.validateValues" -}}
  137. {{- $messages := list -}}
  138. {{- $messages := without $messages "" -}}
  139. {{- $message := join "\n" $messages -}}
  140. {{- if $message -}}
  141. {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
  142. {{- end -}}
  143. {{- end -}}