e2e14018086f3452b2d27c6237d2df422eace066
[demo.git] / tutorials / ApacheCNF / templates / cba / Templates / k8s-configs / deployment-config / templates / _helpers.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
3 Expand the name of the chart.
4 */}}
5 {{- define "apache.name" -}}
6 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7 {{- end -}}
8
9 {{/*
10 Create a default fully qualified app name.
11 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12 */}}
13 {{- define "apache.fullname" -}}
14 {{- if .Values.fullnameOverride -}}
15 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
16 {{- else -}}
17 {{- $name := default .Chart.Name .Values.nameOverride -}}
18 {{- if contains $name .Release.Name -}}
19 {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
20 {{- else -}}
21 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
22 {{- end -}}
23 {{- end -}}
24 {{- end -}}
25
26 {{/*
27 Common labels
28 */}}
29 {{- define "apache.labels" -}}
30 app.kubernetes.io/name: {{ include "apache.name" . }}
31 helm.sh/chart: {{ include "apache.chart" . }}
32 app.kubernetes.io/instance: {{ .Release.Name }}
33 app.kubernetes.io/managed-by: {{ .Release.Service }}
34 {{- end -}}
35
36 {{/*
37 Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
38 */}}
39 {{- define "apache.matchLabels" -}}
40 app.kubernetes.io/name: {{ include "apache.name" . }}
41 app.kubernetes.io/instance: {{ .Release.Name }}
42 {{- end -}}
43
44 {{/*
45 Return the proper Apache image name
46 */}}
47 {{- define "apache.image" -}}
48 {{- $registryName := .Values.image.registry -}}
49 {{- $repositoryName := .Values.image.repository -}}
50 {{- $tag := .Values.image.tag | toString -}}
51 {{/*
52 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
53 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
54 Also, we can't use a single if because lazy evaluation is not an option
55 */}}
56 {{- if .Values.global }}
57     {{- if .Values.global.imageRegistry }}
58         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
59     {{- else -}}
60         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
61     {{- end -}}
62 {{- else -}}
63     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
64 {{- end -}}
65 {{- end -}}
66
67 {{/*
68 Return the proper Apache Docker Image Registry Secret Names
69 */}}
70 {{- define "apache.imagePullSecrets" -}}
71 {{/*
72 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
73 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
74 Also, we can't use a single if because lazy evaluation is not an option
75 */}}
76 {{- if .Values.global }}
77 {{- if .Values.global.imagePullSecrets }}
78 imagePullSecrets:
79 {{- range .Values.global.imagePullSecrets }}
80   - name: {{ . }}
81 {{- end }}
82 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
83 imagePullSecrets:
84 {{- range .Values.image.pullSecrets }}
85   - name: {{ . }}
86 {{- end }}
87 {{- range .Values.metrics.image.pullSecrets }}
88   - name: {{ . }}
89 {{- end }}
90 {{- end -}}
91 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
92 imagePullSecrets:
93 {{- range .Values.image.pullSecrets }}
94   - name: {{ . }}
95 {{- end }}
96 {{- range .Values.metrics.image.pullSecrets }}
97   - name: {{ . }}
98 {{- end }}
99 {{- end -}}
100 {{- end -}}
101
102 {{/*
103 Return the proper image name (for the metrics image)
104 */}}
105 {{- define "apache.metrics.image" -}}
106 {{- $registryName := .Values.metrics.image.registry -}}
107 {{- $repositoryName := .Values.metrics.image.repository -}}
108 {{- $tag := .Values.metrics.image.tag | toString -}}
109 {{/*
110 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
111 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
112 Also, we can't use a single if because lazy evaluation is not an option
113 */}}
114 {{- if .Values.global }}
115     {{- if .Values.global.imageRegistry }}
116         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
117     {{- else -}}
118         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
119     {{- end -}}
120 {{- else -}}
121     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
122 {{- end -}}
123 {{- end -}}
124
125 {{/*
126 Return true if mouting a static web page
127 */}}
128 {{- define "apache.useHtdocs" -}}
129 {{ default "" (or .Values.cloneHtdocsFromGit.enabled .Values.htdocsConfigMap .Values.htdocsPVC) }}
130 {{- end -}}
131
132 {{/*
133 Return associated volume
134 */}}
135 {{- define "apache.htdocsVolume" -}}
136 {{- if .Values.cloneHtdocsFromGit.enabled }}
137 emptyDir: {}
138 {{- else if .Values.htdocsConfigMap }}
139 configMap:
140   name: {{ .Values.htdocsConfigMap }}
141 {{- else if .Values.htdocsPVC }}
142 persistentVolumeClaim:
143   claimName: {{ .Values.htdocsPVC }}
144 {{- end }}
145 {{- end -}}
146
147 {{/*
148 Validate data
149 */}}
150 {{- define "apache.validateValues" -}}
151 {{- $messages := list -}}
152 {{- $messages := append $messages (include "apache.validateValues.htdocs" .) -}}
153 {{- $messages := append $messages (include "apache.validateValues.htdocsGit" .) -}}
154 {{- $messages := without $messages "" -}}
155 {{- $message := join "\n" $messages -}}
156  {{- if $message -}}
157 {{-   printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
158 {{- end -}}
159 {{- end -}}
160
161 {{/*
162 Create chart name and version as used by the chart label.
163 */}}
164 {{- define "apache.chart" -}}
165 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
166 {{- end -}}
167
168 {{/*
169 Validate data (htdocs)
170 */}}
171 {{- define "apache.validateValues.htdocs" -}}
172 {{- if or (and .Values.cloneHtdocsFromGit.enabled (or .Values.htdocsPVC .htdocsConfigMap )) (and .Values.htdocsPVC (or .Values.htdocsConfigMap .Values.cloneHtdocsFromGit.enabled )) (and .Values.htdocsConfigMap (or .Values.htdocsPVC .Values.cloneHtdocsFromGit.enabled )) }}
173 apache: htdocs
174     You have selected more than one way of deploying htdocs. Please select only one of htdocsConfigMap cloneHtdocsFromGit or htdocsVolume
175 {{- end }}
176 {{- end -}}
177
178 {{/*
179 Validate data (htdocs git)
180 */}}
181 {{- define "apache.validateValues.htdocsGit" -}}
182 {{- if .Values.cloneHtdocsFromGit.enabled }}
183   {{- if not .Values.cloneHtdocsFromGit.repository }}
184 apache: htdocs-git-repository
185     You did not specify a git repository to clone. Please set cloneHtdocsFromGit.repository
186   {{- end }}
187   {{- if not .Values.cloneHtdocsFromGit.branch }}
188 apache: htdocs-git-branch
189     You did not specify a branch to checkout in the git repository. Please set cloneHtdocsFromGit.branch
190   {{- end }}
191 {{- end -}}
192 {{- end -}}
193
194 {{/*
195 Validate values of Apache - Incorrect extra volume settings
196 */}}
197 {{- define "apache.validateValues.extraVolumes" -}}
198 {{- if and (.Values.extraVolumes) (not .Values.extraVolumeMounts) -}}
199 apache: missing-extra-volume-mounts
200     You specified extra volumes but not mount points for them. Please set
201     the extraVolumeMounts value
202 {{- end -}}
203 {{- end -}}
204
205 {{/*
206 Return the proper git image name
207 */}}
208 {{- define "git.image" -}}
209 {{- $registryName := .Values.git.registry -}}
210 {{- $repositoryName := .Values.git.repository -}}
211 {{- $tag := .Values.git.tag | toString -}}
212 {{/*
213 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
214 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
215 Also, we can't use a single if because lazy evaluation is not an option
216 */}}
217 {{- if .Values.global }}
218     {{- if .Values.global.imageRegistry }}
219         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
220     {{- else -}}
221         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
222     {{- end -}}
223 {{- else -}}
224     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
225 {{- end -}}
226 {{- end -}}
227
228 {{/*
229 Get the vhosts config map name.
230 */}}
231 {{- define "apache.vhostsConfigMap" -}}
232 {{- if .Values.vhostsConfigMap -}}
233     {{- printf "%s" (tpl .Values.vhostsConfigMap $) -}}
234 {{- else -}}
235     {{- printf "%s-vhosts" (include "apache.fullname" . ) -}}
236 {{- end -}}
237 {{- end -}}
238
239 {{/*
240 Get the httpd.conf config map name.
241 */}}
242 {{- define "apache.httpdConfConfigMap" -}}
243 {{- if .Values.httpdConfConfigMap -}}
244     {{- printf "%s" (tpl .Values.httpdConfConfigMap $) -}}
245 {{- else -}}
246     {{- printf "%s-httpd-conf" (include "apache.fullname" . ) -}}
247 {{- end -}}
248 {{- end -}}
249
250 {{/*
251 Renders a value that contains template.
252 Usage:
253 {{ include "apache.tplValue" ( dict "value" .Values.path.to.the.Value "context" $) }}
254 */}}
255 {{- define "apache.tplValue" -}}
256     {{- if typeIs "string" .value }}
257         {{- tpl .value .context }}
258     {{- else }}
259         {{- tpl (.value | toYaml) .context }}
260     {{- end }}
261 {{- end -}}
262
263