|
| 1 | +{{/* |
| 2 | +Copyright Drycc Community. |
| 3 | +SPDX-License-Identifier: APACHE-2.0 |
| 4 | +*/}} |
| 5 | + |
| 6 | +{{/* vim: set filetype=mustache: */}} |
| 7 | + |
| 8 | +{{- define "mysql.primary.fullname" -}} |
| 9 | +{{- if eq .Values.architecture "replication" }} |
| 10 | +{{- printf "%s-%s" (include "common.names.fullname" .) .Values.primary.name | trunc 63 | trimSuffix "-" -}} |
| 11 | +{{- else -}} |
| 12 | +{{- include "common.names.fullname" . -}} |
| 13 | +{{- end -}} |
| 14 | +{{- end -}} |
| 15 | + |
| 16 | +{{- define "mysql.router.fullname" -}} |
| 17 | +{{- printf "%s-%s" (include "common.names.fullname" .) .Values.router.name | trunc 63 | trimSuffix "-" -}} |
| 18 | +{{- end -}} |
| 19 | + |
| 20 | + |
| 21 | +{{- define "mysql.cluster.fullname" -}} |
| 22 | +{{- printf "%s-%s" (include "common.names.fullname" .) .Values.cluster.name | trunc 63 | trimSuffix "-" -}} |
| 23 | +{{- end -}} |
| 24 | + |
| 25 | +{{/* |
| 26 | +Return the proper MySQL image name |
| 27 | +*/}} |
| 28 | +{{- define "mysql.image" -}} |
| 29 | +{{- include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }} |
| 30 | +{{- end -}} |
| 31 | + |
| 32 | +{{/* |
| 33 | +Return the proper Router image name |
| 34 | +*/}} |
| 35 | +{{- define "router.image" -}} |
| 36 | +{{- include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }} |
| 37 | +{{- end -}} |
| 38 | + |
| 39 | +{{/* |
| 40 | +Return the proper Cluster image name |
| 41 | +*/}} |
| 42 | +{{- define "cluster.image" -}} |
| 43 | +{{- include "common.images.image" (dict "imageRoot" .Values.cluster.image "global" .Values.global) }} |
| 44 | +{{- end -}} |
| 45 | + |
| 46 | +{{/* |
| 47 | +Return the proper metrics image name |
| 48 | +*/}} |
| 49 | +{{- define "mysql.metrics.image" -}} |
| 50 | +{{- include "common.images.image" (dict "imageRoot" .Values.metrics.image "global" .Values.global) }} |
| 51 | +{{- end -}} |
| 52 | + |
| 53 | +{{/* |
| 54 | +Return the proper image name (for the init container volume-permissions image) |
| 55 | +*/}} |
| 56 | +{{- define "mysql.volumePermissions.image" -}} |
| 57 | +{{- include "common.images.image" (dict "imageRoot" .Values.volumePermissions.image "global" .Values.global) }} |
| 58 | +{{- end -}} |
| 59 | + |
| 60 | +{{/* |
| 61 | +Return the proper Docker Image Registry Secret Names |
| 62 | +*/}} |
| 63 | +{{- define "mysql.imagePullSecrets" -}} |
| 64 | +{{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.metrics.image .Values.volumePermissions.image) "global" .Values.global) }} |
| 65 | +{{- end -}} |
| 66 | + |
| 67 | +{{/* |
| 68 | +Get the initialization scripts ConfigMap name. |
| 69 | +*/}} |
| 70 | +{{- define "mysql.initdbScriptsCM" -}} |
| 71 | +{{- if .Values.initdbScriptsConfigMap -}} |
| 72 | + {{- printf "%s" (tpl .Values.initdbScriptsConfigMap $) -}} |
| 73 | +{{- else -}} |
| 74 | + {{- printf "%s-init-scripts" (include "mysql.primary.fullname" .) -}} |
| 75 | +{{- end -}} |
| 76 | +{{- end -}} |
| 77 | + |
| 78 | +{{/* |
| 79 | + Returns the proper service account name depending if an explicit service account name is set |
| 80 | + in the values file. If the name is not set it will default to either mysql.fullname if serviceAccount.create |
| 81 | + is true or default otherwise. |
| 82 | +*/}} |
| 83 | +{{- define "mysql.serviceAccountName" -}} |
| 84 | + {{- if .Values.serviceAccount.create -}} |
| 85 | + {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }} |
| 86 | + {{- else -}} |
| 87 | + {{ default "default" .Values.serviceAccount.name }} |
| 88 | + {{- end -}} |
| 89 | +{{- end -}} |
| 90 | + |
| 91 | +{{/* |
| 92 | +Return the configmap with the MySQL Primary configuration |
| 93 | +*/}} |
| 94 | +{{- define "mysql.primary.configmapName" -}} |
| 95 | +{{- if .Values.primary.existingConfigmap -}} |
| 96 | + {{- printf "%s" (tpl .Values.primary.existingConfigmap $) -}} |
| 97 | +{{- else -}} |
| 98 | + {{- printf "%s" (include "mysql.primary.fullname" .) -}} |
| 99 | +{{- end -}} |
| 100 | +{{- end -}} |
| 101 | + |
| 102 | +{{/* |
| 103 | +Return the configmap with the MySQL Router configuration |
| 104 | +*/}} |
| 105 | +{{- define "mysql.router.configmapName" -}} |
| 106 | +{{- if .Values.router.existingConfigmap -}} |
| 107 | + {{- printf "%s" (tpl .Values.router.existingConfigmap $) -}} |
| 108 | +{{- else -}} |
| 109 | + {{- printf "%s-router" (include "common.names.fullname" .) -}} |
| 110 | +{{- end -}} |
| 111 | +{{- end -}} |
| 112 | + |
| 113 | +{{/* |
| 114 | +Return true if a configmap object should be created for MySQL Secondary |
| 115 | +*/}} |
| 116 | +{{- define "mysql.primary.createConfigmap" -}} |
| 117 | +{{- if and .Values.primary.configuration (not .Values.primary.existingConfigmap) }} |
| 118 | + {{- true -}} |
| 119 | +{{- else -}} |
| 120 | +{{- end -}} |
| 121 | +{{- end -}} |
| 122 | + |
| 123 | +{{/* |
| 124 | +Return true if a configmap object should be created for MySQL router |
| 125 | +*/}} |
| 126 | +{{- define "mysql.router.createConfigmap" -}} |
| 127 | +{{- if and .Values.router.configuration (not .Values.router.existingConfigmap) }} |
| 128 | + {{- true -}} |
| 129 | +{{- else -}} |
| 130 | +{{- end -}} |
| 131 | +{{- end -}} |
| 132 | + |
| 133 | +{{/* |
| 134 | +Return the configmap with the MySQL Primary configuration |
| 135 | +*/}} |
| 136 | +{{- define "mysql.secondary.configmapName" -}} |
| 137 | +{{- if .Values.secondary.existingConfigmap -}} |
| 138 | + {{- printf "%s" (tpl .Values.secondary.existingConfigmap $) -}} |
| 139 | +{{- else -}} |
| 140 | + {{- printf "%s" (include "mysql.secondary.fullname" .) -}} |
| 141 | +{{- end -}} |
| 142 | +{{- end -}} |
| 143 | + |
| 144 | +{{/* |
| 145 | +Return true if a configmap object should be created for MySQL Secondary |
| 146 | +*/}} |
| 147 | +{{- define "mysql.secondary.createConfigmap" -}} |
| 148 | +{{- if and (eq .Values.architecture "replication") .Values.secondary.configuration (not .Values.secondary.existingConfigmap) }} |
| 149 | + {{- true -}} |
| 150 | +{{- else -}} |
| 151 | +{{- end -}} |
| 152 | +{{- end -}} |
| 153 | + |
| 154 | +{{/* |
| 155 | +Return the secret with MySQL credentials |
| 156 | +*/}} |
| 157 | +{{- define "mysql.secretName" -}} |
| 158 | + {{- if .Values.auth.existingSecret -}} |
| 159 | + {{- printf "%s" (tpl .Values.auth.existingSecret $) -}} |
| 160 | + {{- else -}} |
| 161 | + {{- printf "%s" (include "common.names.fullname" .) -}} |
| 162 | + {{- end -}} |
| 163 | +{{- end -}} |
| 164 | + |
| 165 | +{{/* |
| 166 | +Return true if a secret object should be created for MySQL |
| 167 | +*/}} |
| 168 | +{{- define "mysql.createSecret" -}} |
| 169 | +{{- if and (not .Values.auth.existingSecret) (not .Values.auth.customPasswordFiles) }} |
| 170 | + {{- true -}} |
| 171 | +{{- end -}} |
| 172 | +{{- end -}} |
| 173 | + |
| 174 | +{{/* |
| 175 | +Returns the available value for certain key in an existing secret (if it exists), |
| 176 | +otherwise it generates a random value. |
| 177 | +*/}} |
| 178 | +{{- define "getValueFromSecret" }} |
| 179 | + {{- $len := (default 16 .Length) | int -}} |
| 180 | + {{- $obj := (lookup "v1" "Secret" .Namespace .Name).data -}} |
| 181 | + {{- if $obj }} |
| 182 | + {{- index $obj .Key | b64dec -}} |
| 183 | + {{- else -}} |
| 184 | + {{- randAlphaNum $len -}} |
| 185 | + {{- end -}} |
| 186 | +{{- end }} |
| 187 | + |
| 188 | +{{/* Check if there are rolling tags in the images */}} |
| 189 | +{{- define "mysql.checkRollingTags" -}} |
| 190 | +{{- include "common.warnings.rollingTag" .Values.image }} |
| 191 | +{{- include "common.warnings.rollingTag" .Values.metrics.image }} |
| 192 | +{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }} |
| 193 | +{{- end -}} |
| 194 | + |
| 195 | +{{/* |
| 196 | +Compile all warnings into a single message, and call fail. |
| 197 | +*/}} |
| 198 | +{{- define "mysql.validateValues" -}} |
| 199 | +{{- $messages := list -}} |
| 200 | +{{- $messages := without $messages "" -}} |
| 201 | +{{- $message := join "\n" $messages -}} |
| 202 | + |
| 203 | +{{- if $message -}} |
| 204 | +{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} |
| 205 | +{{- end -}} |
| 206 | +{{- end -}} |
0 commit comments