Abdelmuhaimen Seaudi | 988aeed | 2021-09-23 21:11:44 +0000 | [diff] [blame] | 1 | {{/* |
| 2 | # Copyright © 2021 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 | apiVersion: batch/v1 |
| 18 | kind: Job |
| 19 | metadata: |
| 20 | name: {{ include "common.fullname" . }}-config-job |
| 21 | namespace: {{ include "common.namespace" . }} |
| 22 | labels: |
| 23 | app: {{ include "common.name" . }} |
| 24 | chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} |
| 25 | release: {{ include "common.release" . }} |
| 26 | heritage: {{ .Release.Service }} |
| 27 | spec: |
| 28 | backoffLimit: 20 |
| 29 | template: |
| 30 | metadata: |
| 31 | labels: |
| 32 | app: {{ include "common.name" . }} |
| 33 | release: {{ include "common.release" . }} |
| 34 | name: {{ include "common.name" . }} |
| 35 | spec: |
| 36 | initContainers: |
| 37 | - name: {{ include "common.name" . }}-readiness |
| 38 | command: |
| 39 | - /app/ready.py |
| 40 | args: |
| 41 | - --container-name |
| 42 | - {{ .Values.global.postgres.container.name }} |
| 43 | env: |
| 44 | - name: NAMESPACE |
| 45 | valueFrom: |
| 46 | fieldRef: |
| 47 | apiVersion: v1 |
| 48 | fieldPath: metadata.namespace |
| 49 | image: {{ include "repositoryGenerator.image.readiness" . }} |
| 50 | imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} |
| 51 | containers: |
| 52 | - command: |
| 53 | - sh |
| 54 | args: |
| 55 | - -c |
| 56 | - | |
| 57 | function prepare_password { |
| 58 | echo -n $1 | sed -e "s/'/''/g" |
| 59 | } |
| 60 | export PG_PASSWORD=`prepare_password $PG_PASSWORD_INPUT`; |
| 61 | export PG_ROOT_PASSWORD=`prepare_password $PG_ROOT_PASSWORD_INPUT`; |
Andreas Geissler | 0239815 | 2022-05-10 10:30:11 +0200 | [diff] [blame] | 62 | {{- if include "common.onServiceMesh" . }} |
| 63 | echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }} |
Abdelmuhaimen Seaudi | 988aeed | 2021-09-23 21:11:44 +0000 | [diff] [blame] | 64 | cd /config-input && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/config/${PFILE}; done; |
| 65 | psql "postgresql://postgres:$PG_ROOT_PASSWORD@$PG_HOST" < /config/setup.sql |
| 66 | env: |
| 67 | - name: PG_HOST |
| 68 | value: "{{ .Values.global.postgres.service.name2 }}" |
| 69 | - name: PG_PRIMARY_USER |
| 70 | value: primaryuser |
| 71 | - name: MODE |
| 72 | value: postgres |
| 73 | - name: PG_PRIMARY_PASSWORD_INPUT |
| 74 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }} |
| 75 | - name: PG_USER |
| 76 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }} |
| 77 | - name: PG_PASSWORD_INPUT |
| 78 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }} |
| 79 | - name: PG_DATABASE |
| 80 | value: "{{ .Values.config.pgDatabase }}" |
| 81 | - name: PG_ROOT_PASSWORD_INPUT |
| 82 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }} |
| 83 | volumeMounts: |
| 84 | - mountPath: /config-input/setup.sql |
| 85 | name: config |
| 86 | subPath: setup.sql |
| 87 | - mountPath: /config |
| 88 | name: pgconf |
| 89 | image: {{ include "repositoryGenerator.image.postgres" . }} |
| 90 | imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} |
| 91 | name: {{ include "common.name" . }}-update-config |
| 92 | volumeMounts: |
| 93 | - mountPath: /etc/localtime |
| 94 | name: localtime |
| 95 | readOnly: true |
| 96 | - mountPath: /config-input/setup.sql |
| 97 | name: config |
| 98 | subPath: setup.sql |
| 99 | - mountPath: /config |
| 100 | name: pgconf |
miroslavmasaryk | a7ac7f0 | 2023-03-01 14:12:26 +0100 | [diff] [blame^] | 101 | resources: {{ include "common.resources" . | nindent 10 }} |
Andreas Geissler | 0239815 | 2022-05-10 10:30:11 +0200 | [diff] [blame] | 102 | {{ include "common.waitForJobContainer" . | indent 6 | trim }} |
Abdelmuhaimen Seaudi | 988aeed | 2021-09-23 21:11:44 +0000 | [diff] [blame] | 103 | {{- if .Values.nodeSelector }} |
| 104 | nodeSelector: |
| 105 | {{ toYaml .Values.nodeSelector | indent 10 }} |
| 106 | {{- end -}} |
| 107 | {{- if .Values.affinity }} |
| 108 | affinity: |
| 109 | {{ toYaml .Values.affinity | indent 10 }} |
| 110 | {{- end }} |
| 111 | volumes: |
| 112 | - name: localtime |
| 113 | hostPath: |
| 114 | path: /etc/localtime |
| 115 | - name: config |
| 116 | configMap: |
| 117 | name: {{ include "common.fullname" . }} |
| 118 | - name: pgconf |
| 119 | emptyDir: |
| 120 | medium: Memory |
| 121 | restartPolicy: Never |
| 122 | imagePullSecrets: |
| 123 | - name: "{{ include "common.namespace" . }}-docker-registry-key" |