Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / mongodb / common / templates / validations / _mysql.tpl
1 {{/*
2 Copyright VMware, Inc.
3 SPDX-License-Identifier: APACHE-2.0
4 */}}
5
6 {{/* vim: set filetype=mustache: */}}
7 {{/*
8 Validate MySQL required passwords are not empty.
9
10 Usage:
11 {{ include "common.validations.values.mysql.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
12 Params:
13   - secret - String - Required. Name of the secret where MySQL values are stored, e.g: "mysql-passwords-secret"
14   - subchart - Boolean - Optional. Whether MySQL is used as subchart or not. Default: false
15 */}}
16 {{- define "common.validations.values.mysql.passwords" -}}
17   {{- $existingSecret := include "common.mysql.values.auth.existingSecret" . -}}
18   {{- $enabled := include "common.mysql.values.enabled" . -}}
19   {{- $architecture := include "common.mysql.values.architecture" . -}}
20   {{- $authPrefix := include "common.mysql.values.key.auth" . -}}
21   {{- $valueKeyRootPassword := printf "%s.rootPassword" $authPrefix -}}
22   {{- $valueKeyUsername := printf "%s.username" $authPrefix -}}
23   {{- $valueKeyPassword := printf "%s.password" $authPrefix -}}
24   {{- $valueKeyReplicationPassword := printf "%s.replicationPassword" $authPrefix -}}
25
26   {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
27     {{- $requiredPasswords := list -}}
28
29     {{- $requiredRootPassword := dict "valueKey" $valueKeyRootPassword "secret" .secret "field" "mysql-root-password" -}}
30     {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
31
32     {{- $valueUsername := include "common.utils.getValueFromKey" (dict "key" $valueKeyUsername "context" .context) }}
33     {{- if not (empty $valueUsername) -}}
34         {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "mysql-password" -}}
35         {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
36     {{- end -}}
37
38     {{- if (eq $architecture "replication") -}}
39         {{- $requiredReplicationPassword := dict "valueKey" $valueKeyReplicationPassword "secret" .secret "field" "mysql-replication-password" -}}
40         {{- $requiredPasswords = append $requiredPasswords $requiredReplicationPassword -}}
41     {{- end -}}
42
43     {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
44
45   {{- end -}}
46 {{- end -}}
47
48 {{/*
49 Auxiliary function to get the right value for existingSecret.
50
51 Usage:
52 {{ include "common.mysql.values.auth.existingSecret" (dict "context" $) }}
53 Params:
54   - subchart - Boolean - Optional. Whether MySQL is used as subchart or not. Default: false
55 */}}
56 {{- define "common.mysql.values.auth.existingSecret" -}}
57   {{- if .subchart -}}
58     {{- .context.Values.mysql.auth.existingSecret | quote -}}
59   {{- else -}}
60     {{- .context.Values.auth.existingSecret | quote -}}
61   {{- end -}}
62 {{- end -}}
63
64 {{/*
65 Auxiliary function to get the right value for enabled mysql.
66
67 Usage:
68 {{ include "common.mysql.values.enabled" (dict "context" $) }}
69 */}}
70 {{- define "common.mysql.values.enabled" -}}
71   {{- if .subchart -}}
72     {{- printf "%v" .context.Values.mysql.enabled -}}
73   {{- else -}}
74     {{- printf "%v" (not .context.Values.enabled) -}}
75   {{- end -}}
76 {{- end -}}
77
78 {{/*
79 Auxiliary function to get the right value for architecture
80
81 Usage:
82 {{ include "common.mysql.values.architecture" (dict "subchart" "true" "context" $) }}
83 Params:
84   - subchart - Boolean - Optional. Whether MySQL is used as subchart or not. Default: false
85 */}}
86 {{- define "common.mysql.values.architecture" -}}
87   {{- if .subchart -}}
88     {{- .context.Values.mysql.architecture -}}
89   {{- else -}}
90     {{- .context.Values.architecture -}}
91   {{- end -}}
92 {{- end -}}
93
94 {{/*
95 Auxiliary function to get the right value for the key auth
96
97 Usage:
98 {{ include "common.mysql.values.key.auth" (dict "subchart" "true" "context" $) }}
99 Params:
100   - subchart - Boolean - Optional. Whether MySQL is used as subchart or not. Default: false
101 */}}
102 {{- define "common.mysql.values.key.auth" -}}
103   {{- if .subchart -}}
104     mysql.auth
105   {{- else -}}
106     auth
107   {{- end -}}
108 {{- end -}}