Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 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 |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 20 | There are two formats available. |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 21 | |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 22 | The simple one (where wait_for is just list of containers): |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 23 | |
| 24 | wait_for: |
| 25 | - aaf-locate |
| 26 | - aaf-cm |
| 27 | - aaf-service |
| 28 | |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 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 | |
Sylvain Desbureaux | 79a4467 | 2020-12-08 17:54:23 +0100 | [diff] [blame] | 38 | the powerful one allows also to wait for jobs with this: |
| 39 | wait_for: |
| 40 | name: myname |
| 41 | jobs: |
| 42 | - '{{ include "common.release" . }}-the-job' |
| 43 | |
| 44 | Be careful, as on the example above, the job name may have a "non fixed" name |
| 45 | and thus don't forget to use templates if needed |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 46 | |
| 47 | The function can takes below arguments (inside a dictionary): |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 48 | - .dot : environment (.) |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 49 | - .initRoot : the root dictionary of readinessCheck submodule |
| 50 | (default to .Values.readinessCheck) |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 51 | - .wait_for : list of containers / jobs to wait for (default to |
| 52 | .Values.wait_for) |
| 53 | |
| 54 | Example calls: |
| 55 | {{ include "common.readinessCheck.waitFor" . }} |
| 56 | {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.where.my.wait_for.is ) }} |
| 57 | */}} |
| 58 | {{- define "common.readinessCheck.waitFor" -}} |
| 59 | {{- $dot := default . .dot -}} |
| 60 | {{- $initRoot := default $dot.Values.readinessCheck .initRoot -}} |
| 61 | {{/* Our version of helm doesn't support deepCopy so we need this nasty trick */}} |
Sylvain Desbureaux | 8c18404 | 2020-05-25 13:05:45 +0200 | [diff] [blame] | 62 | {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }} |
| 63 | {{- $wait_for := default $initRoot.wait_for .wait_for -}} |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 64 | {{- $containers := index (ternary (dict "containers" $wait_for) $wait_for (kindIs "slice" $wait_for)) "containers" -}} |
| 65 | {{- $namePart := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "name" -}} |
Sylvain Desbureaux | 79a4467 | 2020-12-08 17:54:23 +0100 | [diff] [blame] | 66 | {{- $jobs := index (ternary (dict) $wait_for (kindIs "slice" $wait_for)) "jobs" -}} |
Krzysztof Opasiak | e00bd6a | 2020-07-16 21:02:56 +0200 | [diff] [blame] | 67 | - name: {{ include "common.name" $dot }}{{ ternary "" (printf "-%s" $namePart) (empty $namePart) }}-readiness |
Sylvain Desbureaux | 6cda610 | 2020-11-19 16:56:22 +0100 | [diff] [blame] | 68 | image: {{ include "repositoryGenerator.image.readiness" $subchartDot }} |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 69 | imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }} |
Sylvain Desbureaux | 82f041d | 2021-02-25 14:17:55 +0100 | [diff] [blame] | 70 | securityContext: |
| 71 | runAsUser: {{ $subchartDot.Values.user }} |
| 72 | runAsGroup: {{ $subchartDot.Values.group }} |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 73 | command: |
Sylvain Desbureaux | 1694e1d | 2020-08-21 09:58:25 +0200 | [diff] [blame] | 74 | - /app/ready.py |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 75 | args: |
Sylvain Desbureaux | 79a4467 | 2020-12-08 17:54:23 +0100 | [diff] [blame] | 76 | {{- range $container := default (list) $containers }} |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 77 | - --container-name |
| 78 | - {{ tpl $container $dot }} |
| 79 | {{- end }} |
Sylvain Desbureaux | 79a4467 | 2020-12-08 17:54:23 +0100 | [diff] [blame] | 80 | {{- range $job := $jobs }} |
| 81 | - --job-name |
| 82 | - {{ tpl $job $dot }} |
| 83 | {{- end }} |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 84 | env: |
| 85 | - name: NAMESPACE |
| 86 | valueFrom: |
| 87 | fieldRef: |
| 88 | apiVersion: v1 |
| 89 | fieldPath: metadata.namespace |
| 90 | resources: |
| 91 | limits: |
| 92 | cpu: {{ $subchartDot.Values.limits.cpu }} |
| 93 | memory: {{ $subchartDot.Values.limits.memory }} |
| 94 | requests: |
| 95 | cpu: {{ $subchartDot.Values.requests.cpu }} |
| 96 | memory: {{ $subchartDot.Values.requests.memory }} |
| 97 | {{- end -}} |