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