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