[MARIADB][COMMON] Add support for mariadb-operator
[oom.git] / kubernetes / common / readinessCheck / templates / _readinessCheck.tpl
1 {{/*
2 # Copyright © 2020 Orange
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 */}}
16
17 {{/*
18   Generate readiness part for a pod
19   Will look by default to .Values.wait_for
20   There are two formats available.
21
22   The simple one (where wait_for is just list of containers):
23
24   wait_for:
25     - aaf-locate
26     - aaf-cm
27     - aaf-service
28
29   The powerful one (where wait_for is a map):
30
31   wait_for:
32     name: myname
33     containers:
34       - aaf-locate
35       - aaf-cm
36       - aaf-service
37
38   the powerful one allows also to wait for pod names with this
39   (has to start with the given pod name):
40   wait_for:
41     name: myname
42     pods:
43       - test-pod
44
45   the powerful one allows also to wait for pods with the
46   given "app" label:
47   wait_for:
48     name: myname
49     apps:
50       - mariadb-galera
51
52   the powerful one allows also to wait for jobs with this:
53   wait_for:
54     name: myname
55     jobs:
56       - '{{ include "common.release" . }}-the-job'
57
58   Be careful, as on the example above, the job name may have a "non fixed" name
59   and thus don't forget to use templates if needed
60
61   The function can takes below arguments (inside a dictionary):
62      - .dot : environment (.)
63      - .initRoot : the root dictionary of readinessCheck submodule
64                    (default to .Values.readinessCheck)
65      - .wait_for : list of containers / pods /apps / jobs to wait for (default to
66                    .Values.wait_for)
67
68   Example calls:
69     {{ include "common.readinessCheck.waitFor" . }}
70     {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.where.my.wait_for.is ) }}
71 */}}
72 {{- define "common.readinessCheck.waitFor" -}}
73 {{-   $dot := default . .dot -}}
74 {{-   $initRoot := default $dot.Values.readinessCheck .initRoot -}}
75 {{/*  Our version of helm doesn't support deepCopy so we need this nasty trick */}}
76 {{-   $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
77 {{-   $wait_for := default $initRoot.wait_for .wait_for -}}
78 {{-   $containers := index (ternary (dict "containers" $wait_for) $wait_for (kindIs "slice" $wait_for)) "containers" -}}
79 {{-   $pods := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "pods" -}}
80 {{-   $apps := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "apps" -}}
81 {{-   $namePart := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "name" -}}
82 {{-   $jobs := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "jobs" -}}
83 - name: {{ include "common.name" $dot }}{{ ternary "" (printf "-%s" $namePart) (empty $namePart) }}-readiness
84   image: {{ include "repositoryGenerator.image.readiness" $subchartDot }}
85   imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
86   securityContext:
87     runAsUser: {{ $subchartDot.Values.user }}
88     runAsGroup: {{ $subchartDot.Values.group }}
89   command:
90   - /app/ready.py
91   args:
92   {{- range $container := default (list) $containers }}
93   - --container-name
94   - {{ tpl $container $dot }}
95   {{- end }}
96   {{- range $pod := default (list) $pods }}
97   - --pod-name
98   - {{ tpl $pod $dot }}
99   {{- end }}
100   {{- range $app := default (list) $apps }}
101   - --app-name
102   - {{ tpl $app $dot }}
103   {{- end }}
104   {{- range $job := $jobs }}
105   - --job-name
106   - {{ tpl $job $dot }}
107   {{- end }}
108   env:
109   - name: NAMESPACE
110   {{- if $subchartDot.Values.namespace }}
111     value: {{ $subchartDot.Values.namespace }}
112   {{- else }}
113     valueFrom:
114       fieldRef:
115         apiVersion: v1
116         fieldPath: metadata.namespace
117   {{- end }}
118   resources:
119     limits:
120       cpu: {{ $subchartDot.Values.limits.cpu }}
121       memory: {{ $subchartDot.Values.limits.memory }}
122     requests:
123       cpu: {{ $subchartDot.Values.requests.cpu }}
124       memory: {{ $subchartDot.Values.requests.memory }}
125 {{- end -}}