|
| 1 | +{{- if .Values.seedData.enabled }} |
| 2 | +apiVersion: batch/v1 |
| 3 | +kind: Job |
| 4 | +metadata: |
| 5 | + name: {{ include "common.names.fullname" $ }}-seed-data-{{ .Release.Revision }} |
| 6 | + labels: |
| 7 | + {{- include "spar.labels" . | nindent 4 }} |
| 8 | + annotations: |
| 9 | + # Run after the release's resources are in place (post-install) and on every |
| 10 | + # upgrade. The script itself waits for the DB and the `strategy` table |
| 11 | + # (created by the API `migrate`), so it is resilient to ordering. |
| 12 | + "helm.sh/hook": post-install,post-upgrade |
| 13 | + "helm.sh/hook-weight": "5" |
| 14 | + # Keep the Job after a successful run (do NOT use hook-succeeded) so it stays |
| 15 | + # visible for inspection; it's removed before the next run (before-hook-creation) |
| 16 | + # and garbage-collected by ttlSecondsAfterFinished. |
| 17 | + "helm.sh/hook-delete-policy": before-hook-creation |
| 18 | +spec: |
| 19 | + backoffLimit: 6 |
| 20 | + ttlSecondsAfterFinished: 600 |
| 21 | + template: |
| 22 | + metadata: |
| 23 | + labels: |
| 24 | + {{- include "spar.labels" . | nindent 8 }} |
| 25 | + spec: |
| 26 | + restartPolicy: OnFailure |
| 27 | + {{- with .Values.sparMapperAPI.imagePullSecrets }} |
| 28 | + imagePullSecrets: |
| 29 | + {{- toYaml . | nindent 8 }} |
| 30 | + {{- end }} |
| 31 | + containers: |
| 32 | + - name: seed-data |
| 33 | + image: {{ .Values.seedData.image }} |
| 34 | + env: |
| 35 | + - name: PGHOST |
| 36 | + value: '{{ tpl .Values.global.postgresqlHost $ }}' |
| 37 | + - name: PGPORT |
| 38 | + value: "5432" |
| 39 | + - name: PGDATABASE |
| 40 | + value: '{{ tpl .Values.global.sparDB $ }}' |
| 41 | + - name: PGUSER |
| 42 | + value: '{{ tpl .Values.global.sparDBUser $ }}' |
| 43 | + - name: PGPASSWORD |
| 44 | + valueFrom: |
| 45 | + secretKeyRef: |
| 46 | + name: '{{ tpl .Values.global.sparDBSecret $ }}' |
| 47 | + key: '{{ tpl .Values.global.sparDBUserPasswordKey $ }}' |
| 48 | + command: |
| 49 | + - sh |
| 50 | + - -c |
| 51 | + - | |
| 52 | + set -e |
| 53 | + echo "Waiting for database ${PGHOST}:${PGPORT}/${PGDATABASE} ..." |
| 54 | + until pg_isready -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE"; do sleep 3; done |
| 55 | + echo "Waiting for 'strategy' table (created by the API migrate) ..." |
| 56 | + until [ -n "$(psql -tAc "SELECT to_regclass('public.strategy')")" ]; do sleep 5; done |
| 57 | + echo "Seeding strategy table ..." |
| 58 | + psql -v ON_ERROR_STOP=1 -f /seed/seed.sql |
| 59 | + echo "Seed complete." |
| 60 | + volumeMounts: |
| 61 | + - name: seed-sql |
| 62 | + mountPath: /seed |
| 63 | + readOnly: true |
| 64 | + volumes: |
| 65 | + - name: seed-sql |
| 66 | + configMap: |
| 67 | + name: {{ include "common.names.fullname" $ }}-seed-data |
| 68 | +{{- end }} |
0 commit comments