2 # Copyright © 2020 Orange
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 Generate readiness part for a pod
19 Will look by default to .Values.wait_for
20 There are two formats available.
22 The simple one (where wait_for is just list of containers):
29 The powerful one (where wait_for is a map):
38 the powerful one allows also to wait for pod names with this
39 (has to start with the given pod name):
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:
51 - mariadb-galera-service
53 the powerful one allows also to wait for pods with the
60 the powerful one allows also to wait for jobs with this:
64 - '{{ include "common.release" . }}-the-job'
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
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)
77 {{ include "common.readinessCheck.waitFor" . }}
78 {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.where.my.wait_for.is ) }}
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 }}
96 runAsUser: {{ $subchartDot.Values.user }}
97 runAsGroup: {{ $subchartDot.Values.group }}
101 {{- range $container := default (list) $containers }}
103 - {{ tpl $container $dot }}
105 {{- range $pod := default (list) $pods }}
107 - {{ tpl $pod $dot }}
109 {{- range $service := default (list) $services }}
111 - {{ tpl $service $dot }}
113 {{- range $app := default (list) $apps }}
115 - {{ tpl $app $dot }}
117 {{- range $job := $jobs }}
119 - {{ tpl $job $dot }}
123 {{- if $subchartDot.Values.namespace }}
124 value: {{ $subchartDot.Values.namespace }}
129 fieldPath: metadata.namespace
133 cpu: {{ $subchartDot.Values.limits.cpu }}
134 memory: {{ $subchartDot.Values.limits.memory }}
136 cpu: {{ $subchartDot.Values.requests.cpu }}
137 memory: {{ $subchartDot.Values.requests.memory }}