blob: 6a1a1eb82a76fbe963a1f6fe9a77dacae6ab7454 [file] [log] [blame]
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +02001{{/*
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
Krzysztof Opasiake00bd6a2020-07-16 21:02:56 +020020 There are two formats available.
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020021
Krzysztof Opasiake00bd6a2020-07-16 21:02:56 +020022 The simple one (where wait_for is just list of containers):
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020023
24 wait_for:
25 - aaf-locate
26 - aaf-cm
27 - aaf-service
28
Krzysztof Opasiake00bd6a2020-07-16 21:02:56 +020029 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
39 The function can takes below arguments (inside a dictionary):
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020040 - .dot : environment (.)
Krzysztof Opasiake00bd6a2020-07-16 21:02:56 +020041 - .initRoot : the root dictionary of readinessCheck submodule
42 (default to .Values.readinessCheck)
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020043 - .wait_for : list of containers / jobs to wait for (default to
44 .Values.wait_for)
45
46 Example calls:
47 {{ include "common.readinessCheck.waitFor" . }}
48 {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.where.my.wait_for.is ) }}
49*/}}
50{{- define "common.readinessCheck.waitFor" -}}
51{{- $dot := default . .dot -}}
52{{- $initRoot := default $dot.Values.readinessCheck .initRoot -}}
53{{/* Our version of helm doesn't support deepCopy so we need this nasty trick */}}
Sylvain Desbureaux8c184042020-05-25 13:05:45 +020054{{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
55{{- $wait_for := default $initRoot.wait_for .wait_for -}}
Krzysztof Opasiake00bd6a2020-07-16 21:02:56 +020056{{- $containers := index (ternary (dict "containers" $wait_for) $wait_for (kindIs "slice" $wait_for)) "containers" -}}
57{{- $namePart := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "name" -}}
58- name: {{ include "common.name" $dot }}{{ ternary "" (printf "-%s" $namePart) (empty $namePart) }}-readiness
Sylvain Desbureaux1694e1d2020-08-21 09:58:25 +020059 image: "{{ include "common.repository" $subchartDot }}/{{ $subchartDot.Values.global.readinessImage }}"
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020060 imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
61 command:
Sylvain Desbureaux1694e1d2020-08-21 09:58:25 +020062 - /app/ready.py
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020063 args:
Krzysztof Opasiake00bd6a2020-07-16 21:02:56 +020064 {{- range $container := $containers }}
Sylvain Desbureaux41cf72f2020-05-15 17:25:52 +020065 - --container-name
66 - {{ tpl $container $dot }}
67 {{- end }}
68 env:
69 - name: NAMESPACE
70 valueFrom:
71 fieldRef:
72 apiVersion: v1
73 fieldPath: metadata.namespace
74 resources:
75 limits:
76 cpu: {{ $subchartDot.Values.limits.cpu }}
77 memory: {{ $subchartDot.Values.limits.memory }}
78 requests:
79 cpu: {{ $subchartDot.Values.requests.cpu }}
80 memory: {{ $subchartDot.Values.requests.memory }}
81{{- end -}}