Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / mongodb / common / templates / validations / _postgresql.tpl
1 {{/*
2 Copyright VMware, Inc.
3 SPDX-License-Identifier: APACHE-2.0
4 */}}
5
6 {{/* vim: set filetype=mustache: */}}
7 {{/*
8 Validate PostgreSQL required passwords are not empty.
9
10 Usage:
11 {{ include "common.validations.values.postgresql.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
12 Params:
13   - secret - String - Required. Name of the secret where postgresql values are stored, e.g: "postgresql-passwords-secret"
14   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
15 */}}
16 {{- define "common.validations.values.postgresql.passwords" -}}
17   {{- $existingSecret := include "common.postgresql.values.existingSecret" . -}}
18   {{- $enabled := include "common.postgresql.values.enabled" . -}}
19   {{- $valueKeyPostgresqlPassword := include "common.postgresql.values.key.postgressPassword" . -}}
20   {{- $valueKeyPostgresqlReplicationEnabled := include "common.postgresql.values.key.replicationPassword" . -}}
21   {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
22     {{- $requiredPasswords := list -}}
23     {{- $requiredPostgresqlPassword := dict "valueKey" $valueKeyPostgresqlPassword "secret" .secret "field" "postgresql-password" -}}
24     {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlPassword -}}
25
26     {{- $enabledReplication := include "common.postgresql.values.enabled.replication" . -}}
27     {{- if (eq $enabledReplication "true") -}}
28         {{- $requiredPostgresqlReplicationPassword := dict "valueKey" $valueKeyPostgresqlReplicationEnabled "secret" .secret "field" "postgresql-replication-password" -}}
29         {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlReplicationPassword -}}
30     {{- end -}}
31
32     {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
33   {{- end -}}
34 {{- end -}}
35
36 {{/*
37 Auxiliary function to decide whether evaluate global values.
38
39 Usage:
40 {{ include "common.postgresql.values.use.global" (dict "key" "key-of-global" "context" $) }}
41 Params:
42   - key - String - Required. Field to be evaluated within global, e.g: "existingSecret"
43 */}}
44 {{- define "common.postgresql.values.use.global" -}}
45   {{- if .context.Values.global -}}
46     {{- if .context.Values.global.postgresql -}}
47       {{- index .context.Values.global.postgresql .key | quote -}}
48     {{- end -}}
49   {{- end -}}
50 {{- end -}}
51
52 {{/*
53 Auxiliary function to get the right value for existingSecret.
54
55 Usage:
56 {{ include "common.postgresql.values.existingSecret" (dict "context" $) }}
57 */}}
58 {{- define "common.postgresql.values.existingSecret" -}}
59   {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "existingSecret" "context" .context) -}}
60
61   {{- if .subchart -}}
62     {{- default (.context.Values.postgresql.existingSecret | quote) $globalValue -}}
63   {{- else -}}
64     {{- default (.context.Values.existingSecret | quote) $globalValue -}}
65   {{- end -}}
66 {{- end -}}
67
68 {{/*
69 Auxiliary function to get the right value for enabled postgresql.
70
71 Usage:
72 {{ include "common.postgresql.values.enabled" (dict "context" $) }}
73 */}}
74 {{- define "common.postgresql.values.enabled" -}}
75   {{- if .subchart -}}
76     {{- printf "%v" .context.Values.postgresql.enabled -}}
77   {{- else -}}
78     {{- printf "%v" (not .context.Values.enabled) -}}
79   {{- end -}}
80 {{- end -}}
81
82 {{/*
83 Auxiliary function to get the right value for the key postgressPassword.
84
85 Usage:
86 {{ include "common.postgresql.values.key.postgressPassword" (dict "subchart" "true" "context" $) }}
87 Params:
88   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
89 */}}
90 {{- define "common.postgresql.values.key.postgressPassword" -}}
91   {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "postgresqlUsername" "context" .context) -}}
92
93   {{- if not $globalValue -}}
94     {{- if .subchart -}}
95       postgresql.postgresqlPassword
96     {{- else -}}
97       postgresqlPassword
98     {{- end -}}
99   {{- else -}}
100     global.postgresql.postgresqlPassword
101   {{- end -}}
102 {{- end -}}
103
104 {{/*
105 Auxiliary function to get the right value for enabled.replication.
106
107 Usage:
108 {{ include "common.postgresql.values.enabled.replication" (dict "subchart" "true" "context" $) }}
109 Params:
110   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
111 */}}
112 {{- define "common.postgresql.values.enabled.replication" -}}
113   {{- if .subchart -}}
114     {{- printf "%v" .context.Values.postgresql.replication.enabled -}}
115   {{- else -}}
116     {{- printf "%v" .context.Values.replication.enabled -}}
117   {{- end -}}
118 {{- end -}}
119
120 {{/*
121 Auxiliary function to get the right value for the key replication.password.
122
123 Usage:
124 {{ include "common.postgresql.values.key.replicationPassword" (dict "subchart" "true" "context" $) }}
125 Params:
126   - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false
127 */}}
128 {{- define "common.postgresql.values.key.replicationPassword" -}}
129   {{- if .subchart -}}
130     postgresql.replication.password
131   {{- else -}}
132     replication.password
133   {{- end -}}
134 {{- end -}}