_helpers.tpl 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. {{/*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Return the proper MinIO® image name
  8. */}}
  9. {{- define "minio.image" -}}
  10. {{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
  11. {{- end -}}
  12. {{/*
  13. Return the proper MinIO® Client image name
  14. */}}
  15. {{- define "minio.clientImage" -}}
  16. {{ include "common.images.image" (dict "imageRoot" .Values.clientImage "global" .Values.global) }}
  17. {{- end -}}
  18. {{/*
  19. Return the proper image name (for the init container volume-permissions image)
  20. */}}
  21. {{- define "minio.volumePermissions.image" -}}
  22. {{ include "common.images.image" (dict "imageRoot" .Values.volumePermissions.image "global" .Values.global) }}
  23. {{- end -}}
  24. {{/*
  25. Return the proper Docker Image Registry Secret Names
  26. */}}
  27. {{- define "minio.imagePullSecrets" -}}
  28. {{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image .Values.clientImage .Values.volumePermissions.image) "context" $) -}}
  29. {{- end -}}
  30. {{/*
  31. Returns the available value for certain key in an existing secret (if it exists),
  32. otherwise it generates a random value.
  33. */}}
  34. {{- define "getValueFromSecret" }}
  35. {{- $len := (default 16 .Length) | int -}}
  36. {{- $obj := (lookup "v1" "Secret" .Namespace .Name).data -}}
  37. {{- if $obj }}
  38. {{- index $obj .Key | b64dec -}}
  39. {{- else -}}
  40. {{- randAlphaNum $len -}}
  41. {{- end -}}
  42. {{- end }}
  43. {{/*
  44. Get the user to use to access MinIO®
  45. */}}
  46. {{- define "minio.secret.userValue" -}}
  47. {{- if .Values.auth.rootUser }}
  48. {{- .Values.auth.rootUser -}}
  49. {{- else if (not .Values.auth.forcePassword) }}
  50. {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "root-user") -}}
  51. {{- else -}}
  52. {{ required "A root username is required!" .Values.auth.rootUser }}
  53. {{- end -}}
  54. {{- end -}}
  55. {{/*
  56. Get the password to use to access MinIO®
  57. */}}
  58. {{- define "minio.secret.passwordValue" -}}
  59. {{- if .Values.auth.rootPassword }}
  60. {{- .Values.auth.rootPassword -}}
  61. {{- else if (not .Values.auth.forcePassword) }}
  62. {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "root-password") -}}
  63. {{- else -}}
  64. {{ required "A root password is required!" .Values.auth.rootPassword }}
  65. {{- end -}}
  66. {{- end -}}
  67. {{/*
  68. Get the credentials secret.
  69. */}}
  70. {{- define "minio.secretName" -}}
  71. {{- if .Values.auth.existingSecret -}}
  72. {{- printf "%s" (tpl .Values.auth.existingSecret $) -}}
  73. {{- else -}}
  74. {{- printf "%s" (include "common.names.fullname" .) -}}
  75. {{- end -}}
  76. {{- end -}}
  77. {{/*
  78. Return true if a secret object should be created
  79. */}}
  80. {{- define "minio.createSecret" -}}
  81. {{- if .Values.auth.existingSecret -}}
  82. {{- else -}}
  83. {{- true -}}
  84. {{- end -}}
  85. {{- end -}}
  86. {{/*
  87. Return true if a PVC object should be created (only in standalone mode)
  88. */}}
  89. {{- define "minio.createPVC" -}}
  90. {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) (eq .Values.mode "standalone") }}
  91. {{- true -}}
  92. {{- end -}}
  93. {{- end -}}
  94. {{/*
  95. Return the PVC name (only in standalone mode)
  96. */}}
  97. {{- define "minio.claimName" -}}
  98. {{- if and .Values.persistence.existingClaim }}
  99. {{- printf "%s" (tpl .Values.persistence.existingClaim $) -}}
  100. {{- else -}}
  101. {{- printf "%s" (include "common.names.fullname" .) -}}
  102. {{- end -}}
  103. {{- end -}}
  104. {{/*
  105. Returns the proper service account name depending if an explicit service account name is set
  106. in the values file. If the name is not set it will default to either common.names.fullname if serviceAccount.create
  107. is true or default otherwise.
  108. */}}
  109. {{- define "minio.serviceAccountName" -}}
  110. {{- if .Values.serviceAccount.create -}}
  111. {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
  112. {{- else -}}
  113. {{ default "default" .Values.serviceAccount.name }}
  114. {{- end -}}
  115. {{- end -}}
  116. {{/*
  117. Compile all warnings into a single message, and call fail.
  118. */}}
  119. {{- define "minio.validateValues" -}}
  120. {{- $messages := list -}}
  121. {{- $messages := append $messages (include "minio.validateValues.mode" .) -}}
  122. {{- $messages := append $messages (include "minio.validateValues.totalDrives" .) -}}
  123. {{- $messages := append $messages (include "minio.validateValues.tls" .) -}}
  124. {{- $messages := without $messages "" -}}
  125. {{- $message := join "\n" $messages -}}
  126. {{- if $message -}}
  127. {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
  128. {{- end -}}
  129. {{- end -}}
  130. {{/*
  131. Validate values of MinIO® - must provide a valid mode ("distributed" or "standalone")
  132. */}}
  133. {{- define "minio.validateValues.mode" -}}
  134. {{- $allowedValues := list "distributed" "standalone" }}
  135. {{- if not (has .Values.mode $allowedValues) -}}
  136. minio: mode
  137. Invalid mode selected. Valid values are "distributed" and
  138. "standalone". Please set a valid mode (--set mode="xxxx")
  139. {{- end -}}
  140. {{- end -}}
  141. {{/*
  142. Validate values of MinIO® - total number of drives should be greater than 4
  143. */}}
  144. {{- define "minio.validateValues.totalDrives" -}}
  145. {{- $replicaCount := int .Values.statefulset.replicaCount }}
  146. {{- $drivesPerNode := int .Values.statefulset.drivesPerNode }}
  147. {{- $totalDrives := mul $replicaCount $drivesPerNode }}
  148. {{- if and (eq .Values.mode "distributed") (lt $totalDrives 4) -}}
  149. minio: total drives
  150. The total number of drives should be greater than 4 to guarantee erasure coding!
  151. Please set a combination of nodes, and drives per node that match this condition.
  152. For instance (--set statefulset.replicaCount=2 --set statefulset.drivesPerNode=2)
  153. {{- end -}}
  154. {{- end -}}
  155. {{/*
  156. Validate values of MinIO® - TLS secret must provided if TLS is enabled
  157. */}}
  158. {{- define "minio.validateValues.tls" -}}
  159. {{- if and .Values.tls.enabled (not .Values.tls.existingSecret) (not .Values.tls.autoGenerated) }}
  160. minio: tls.existingSecret, tls.autoGenerated
  161. In order to enable TLS, you also need to provide
  162. an existing secret containing the TLS certificates or
  163. enable auto-generated certificates.
  164. {{- end -}}
  165. {{- end -}}
  166. {{/*
  167. Return the secret containing MinIO TLS certificates
  168. */}}
  169. {{- define "minio.tlsSecretName" -}}
  170. {{- if .Values.tls.existingSecret -}}
  171. {{- printf "%s" (tpl .Values.tls.existingSecret $) -}}
  172. {{- else -}}
  173. {{- printf "%s-crt" (include "common.names.fullname" .) -}}
  174. {{- end -}}
  175. {{- end -}}
  176. {{/*
  177. Return true if a TLS secret object should be created
  178. */}}
  179. {{- define "minio.createTlsSecret" -}}
  180. {{- if and .Values.tls.enabled .Values.tls.autoGenerated (not .Values.tls.existingSecret) }}
  181. {{- true -}}
  182. {{- end -}}
  183. {{- end -}}
  184. {{/*
  185. Provisioning job labels (exclude matchLabels from standard labels)
  186. */}}
  187. {{- define "minio.labels.provisioning" -}}
  188. {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.provisioning.podLabels .Values.commonLabels ) "context" . ) }}
  189. {{- $provisioningLabels := (include "common.labels.standard" ( dict "customLabels" $podLabels "context" $ ) | fromYaml ) -}}
  190. {{- range (include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | fromYaml | keys ) -}}
  191. {{- $_ := unset $provisioningLabels . -}}
  192. {{- end -}}
  193. {{- print ($provisioningLabels | toYaml) -}}
  194. {{- end -}}
  195. {{/*
  196. Return the ingress anotation
  197. */}}
  198. {{- define "minio.ingress.annotations" -}}
  199. {{ .Values.ingress.annotations | toYaml }}
  200. {{- end -}}
  201. {{/*
  202. Return the api ingress anotation
  203. */}}
  204. {{- define "minio.apiIngress.annotations" -}}
  205. {{ .Values.apiIngress.annotations | toYaml }}
  206. {{- end -}}
  207. {{/*
  208. Return the ingress hostname
  209. */}}
  210. {{- define "minio.ingress.hostname" -}}
  211. {{- tpl .Values.ingress.hostname $ -}}
  212. {{- end -}}
  213. {{/*
  214. Return the api ingress hostname
  215. */}}
  216. {{- define "minio.apiIngress.hostname" -}}
  217. {{- tpl .Values.apiIngress.hostname $ -}}
  218. {{- end -}}