Merge "[AAI] Add model-loader tracing config"
[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 a service to be
46   available, which means all pods are deployed, which are
47   selected by the service definition:
48   wait_for:
49     name: myservice
50     services:
51       - mariadb-galera-service
52
53   the powerful one allows also to wait for pods with the
54   given "app" label:
55   wait_for:
56     name: myname
57     apps:
58       - mariadb-galera
59
60   the powerful one allows also to wait for jobs with this:
61   wait_for:
62     name: myname
63     jobs:
64       - '{{ include "common.release" . }}-the-job'
65
66   Be careful, as on the example above, the job name may have a "non fixed" name
67   and thus don't forget to use templates if needed
68
69   The function can takes below arguments (inside a dictionary):
70      - .dot : environment (.)
71      - .initRoot : the root dictionary of readinessCheck submodule
72                    (default to .Values.readinessCheck)
73      - .wait_for : list of service / containers / pods /apps / jobs to wait for
74                    (default to .Values.wait_for)
75
76   Example calls:
77     {{ include "common.readinessCheck.waitFor" . }}
78     {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.where.my.wait_for.is ) }}
79 */}}
80 {{- define "common.readinessCheck.waitFor" -}}
81 {{-   $dot := default . .dot -}}
82 {{-   $initRoot := default $dot.Values.readinessCheck .initRoot -}}
83 {{/*  Our version of helm doesn't support deepCopy so we need this nasty trick */}}
84 {{-   $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
85 {{-   $wait_for := default $initRoot.wait_for .wait_for -}}
86 {{-   $containers := index (ternary (dict "containers" $wait_for) $wait_for (kindIs "slice" $wait_for)) "containers" -}}
87 {{-   $services := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "services" -}}
88 {{-   $pods := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "pods" -}}
89 {{-   $apps := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "apps" -}}
90 {{-   $namePart := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "name" -}}
91 {{-   $jobs := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "jobs" -}}
92 - name: {{ include "common.name" $dot }}{{ ternary "" (printf "-%s" $namePart) (empty $namePart) }}-readiness
93   image: {{ include "repositoryGenerator.image.readiness" $subchartDot }}
94   imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
95   securityContext:
96     runAsUser: {{ $subchartDot.Values.user }}
97     runAsGroup: {{ $subchartDot.Values.group }}
98   command:
99   - /app/ready.py
100   args:
101   {{- range $container := default (list) $containers }}
102   - --container-name
103   - {{ tpl $container $dot }}
104   {{- end }}
105   {{- range $pod := default (list) $pods }}
106   - --pod-name
107   - {{ tpl $pod $dot }}
108   {{- end }}
109   {{- range $service := default (list) $services }}
110   - --service-name
111   - {{ tpl $service $dot }}
112   {{- end }}
113   {{- range $app := default (list) $apps }}
114   - --app-name
115   - {{ tpl $app $dot }}
116   {{- end }}
117   {{- range $job := $jobs }}
118   - --job-name
119   - {{ tpl $job $dot }}
120   {{- end }}
121   env:
122   - name: NAMESPACE
123   {{- if $subchartDot.Values.namespace }}
124     value: {{ $subchartDot.Values.namespace }}
125   {{- else }}
126     valueFrom:
127       fieldRef:
128         apiVersion: v1
129         fieldPath: metadata.namespace
130   {{- end }}
131   resources:
132     limits:
133       cpu: {{ $subchartDot.Values.limits.cpu }}
134       memory: {{ $subchartDot.Values.limits.memory }}
135     requests:
136       cpu: {{ $subchartDot.Values.requests.cpu }}
137       memory: {{ $subchartDot.Values.requests.memory }}
138 {{- end -}}