Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 1 | # Copyright © 2017 Amdocs, Bell Canada |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | {{- if .Values.global.migration.enabled }} |
| 15 | apiVersion: batch/v1 |
| 16 | kind: Job |
| 17 | metadata: |
| 18 | name: {{ include "common.fullname" . }}-backup |
| 19 | namespace: {{ include "common.namespace" . }} |
| 20 | labels: |
| 21 | app: {{ include "common.name" . }} |
| 22 | chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 23 | release: {{ include "common.release" . }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 24 | heritage: {{ .Release.Service }} |
| 25 | annotations: |
| 26 | "helm.sh/hook": pre-upgrade,pre-install |
| 27 | "helm.sh/hook-weight": "1" |
| 28 | "helm.sh/hook-delete-policy": before-hook-creation |
| 29 | spec: |
| 30 | backoffLimit: 20 |
| 31 | template: |
| 32 | metadata: |
| 33 | labels: |
| 34 | app: {{ include "common.name" . }} |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 35 | release: {{ include "common.release" . }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 36 | name: {{ include "common.name" . }} |
| 37 | spec: |
| 38 | containers: |
| 39 | - name: {{ include "common.fullname" . }} |
| 40 | image: "{{ include "common.repository" . }}/{{ .Values.image }}" |
| 41 | imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} |
| 42 | env: |
| 43 | - name: DB_HOST |
| 44 | value: {{ .Values.global.migration.dbHost }} |
| 45 | - name: DB_USER |
Krzysztof Opasiak | 587b6e6 | 2020-03-24 03:26:03 +0100 | [diff] [blame] | 46 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "login") | indent 10 }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 47 | - name: DB_PORT |
| 48 | value: "{{ .Values.global.migration.dbPort }}" |
| 49 | - name: DB_PASS |
Krzysztof Opasiak | 587b6e6 | 2020-03-24 03:26:03 +0100 | [diff] [blame] | 50 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-backup-creds" "key" "password") | indent 10 }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 51 | command: |
| 52 | - /bin/bash |
| 53 | - -c |
| 54 | - mysqldump -vv --user=${DB_USER} --password=${DB_PASS} --host=${DB_HOST} --port=${DB_PORT} --databases --single-transaction --quick --lock-tables=false catalogdb requestdb > /var/data/mariadb/backup-`date +%s`.sql |
| 55 | volumeMounts: |
| 56 | - mountPath: /etc/localtime |
| 57 | name: localtime |
| 58 | readOnly: true |
| 59 | - name: backup-storage |
| 60 | mountPath: /var/data/mariadb |
| 61 | volumes: |
| 62 | - name: localtime |
| 63 | hostPath: |
| 64 | path: /etc/localtime |
| 65 | - name: backup-storage |
| 66 | persistentVolumeClaim: |
| 67 | claimName: {{ include "common.fullname" . }}-migration |
| 68 | imagePullSecrets: |
| 69 | - name: "{{ include "common.namespace" . }}-docker-registry-key" |
| 70 | restartPolicy: Never |
| 71 | --- |
| 72 | {{- end }} |
| 73 | apiVersion: batch/v1 |
| 74 | kind: Job |
| 75 | metadata: |
| 76 | name: {{ include "common.fullname" . }}-config-job |
| 77 | namespace: {{ include "common.namespace" . }} |
| 78 | labels: |
| 79 | app: {{ include "common.name" . }} |
| 80 | chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 81 | release: {{ include "common.release" . }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 82 | heritage: {{ .Release.Service }} |
| 83 | annotations: |
| 84 | "helm.sh/hook": post-upgrade,post-rollback,post-install |
| 85 | "helm.sh/hook-weight": "0" |
| 86 | "helm.sh/hook-delete-policy": before-hook-creation |
| 87 | spec: |
| 88 | backoffLimit: 20 |
| 89 | template: |
| 90 | metadata: |
| 91 | labels: |
| 92 | app: {{ include "common.name" . }}-job |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 93 | release: {{ include "common.release" . }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 94 | name: {{ include "common.name" . }} |
| 95 | spec: |
| 96 | initContainers: |
| 97 | - name: {{ include "common.name" . }}-readiness |
| 98 | command: |
| 99 | - /root/ready.py |
| 100 | args: |
| 101 | - --container-name |
| 102 | - {{ .Values.global.mariadbGalera.nameOverride }} |
| 103 | env: |
| 104 | - name: NAMESPACE |
| 105 | valueFrom: |
| 106 | fieldRef: |
| 107 | apiVersion: v1 |
| 108 | fieldPath: metadata.namespace |
| 109 | image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}" |
| 110 | imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 111 | containers: |
| 112 | - name: {{ include "common.name" . }} |
| 113 | image: "{{ include "common.repository" . }}/{{ .Values.image }}" |
| 114 | imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} |
| 115 | command: |
| 116 | - /bin/bash |
| 117 | - -c |
| 118 | - > |
| 119 | mysql() { /usr/bin/mysql -h ${DB_HOST} -P ${DB_PORT} "$@"; }; |
| 120 | export -f mysql; |
| 121 | mysql --user=root --password=${MYSQL_ROOT_PASSWORD} requestdb -e exit > /dev/null 2>&1 {{ if not .Values.global.migration.enabled }} && echo "Database already initialized!!!" && exit 0 {{ end }}; |
| 122 | for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sh) echo "$0: running $f"; . "$f" ;; *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; *) echo "$0: ignoring $f" ;; esac; echo; done; |
| 123 | {{- if .Values.global.migration.enabled }} |
| 124 | mysql -vv --user=root --password=${MYSQL_ROOT_PASSWORD} < `ls -tr /var/data/mariadb/* | tail -1`; |
| 125 | {{- end }} |
| 126 | env: |
| 127 | - name: DB_HOST |
| 128 | valueFrom: |
| 129 | secretKeyRef: |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 130 | name: {{ include "common.release" . }}-so-db-secrets |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 131 | key: mariadb.readwrite.host |
| 132 | - name: DB_PORT |
| 133 | valueFrom: |
| 134 | secretKeyRef: |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 135 | name: {{ include "common.release" . }}-so-db-secrets |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 136 | key: mariadb.readwrite.port |
| 137 | - name: MYSQL_ROOT_PASSWORD |
Krzysztof Opasiak | 587b6e6 | 2020-03-24 03:26:03 +0100 | [diff] [blame] | 138 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-root-pass" "key" "password") | indent 10 }} |
Krzysztof Opasiak | f68b728 | 2020-03-25 23:22:46 +0100 | [diff] [blame^] | 139 | - name: DB_USER |
| 140 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "login") | indent 10 }} |
| 141 | - name: DB_PASSWORD |
| 142 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-user-creds" "key" "password") | indent 10 }} |
| 143 | - name: DB_ADMIN |
| 144 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "login") | indent 10 }} |
| 145 | - name: DB_ADMIN_PASSWORD |
| 146 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "db-admin-creds" "key" "password") | indent 10 }} |
| 147 | - name: CAMUNDA_DB_USER |
| 148 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "login") | indent 10 }} |
| 149 | - name: CAMUNDA_DB_PASSWORD |
| 150 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "camunda-db-creds" "key" "password") | indent 10 }} |
| 151 | - name: REQUEST_DB_USER |
| 152 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "login") | indent 10 }} |
| 153 | - name: REQUEST_DB_PASSWORD |
| 154 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "request-db-creds" "key" "password") | indent 10 }} |
| 155 | - name: CATALOG_DB_USER |
| 156 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "login") | indent 10 }} |
| 157 | - name: CATALOG_DB_PASSWORD |
| 158 | {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "catalog-db-creds" "key" "password") | indent 10 }} |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 159 | volumeMounts: |
| 160 | - mountPath: /etc/localtime |
| 161 | name: localtime |
| 162 | readOnly: true |
Tomáš Levora | 2a63ef3 | 2019-09-20 08:16:54 +0200 | [diff] [blame] | 163 | - name: docker-entrypoint-initdb-d-sh |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 164 | mountPath: "/docker-entrypoint-initdb.d" |
Tomáš Levora | 2a63ef3 | 2019-09-20 08:16:54 +0200 | [diff] [blame] | 165 | - name: docker-entrypoint-initdb-d-sql |
| 166 | mountPath: "/docker-entrypoint-initdb.d/db-sql-scripts" |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 167 | {{- if .Values.global.migration.enabled }} |
| 168 | - name: backup-storage |
| 169 | mountPath: /var/data/mariadb |
| 170 | {{- end }} |
| 171 | resources: |
| 172 | {{ include "common.resources" . | indent 12 }} |
| 173 | {{- if .Values.nodeSelector }} |
| 174 | nodeSelector: |
| 175 | {{ toYaml .Values.nodeSelector | indent 10 }} |
| 176 | {{- end -}} |
| 177 | {{- if .Values.affinity }} |
| 178 | affinity: |
| 179 | {{ toYaml .Values.affinity | indent 10 }} |
| 180 | {{- end }} |
| 181 | volumes: |
| 182 | - name: localtime |
| 183 | hostPath: |
| 184 | path: /etc/localtime |
Tomáš Levora | 2a63ef3 | 2019-09-20 08:16:54 +0200 | [diff] [blame] | 185 | - name: docker-entrypoint-initdb-d-sh |
| 186 | configMap: |
| 187 | name: {{ include "common.fullname" . }}-mariadb-sh |
| 188 | - name: docker-entrypoint-initdb-d-sql |
| 189 | configMap: |
| 190 | name: {{ include "common.fullname" . }}-mariadb-sql |
Mahendra Raghuwanshi | 72b69c1 | 2019-04-04 10:43:25 +0000 | [diff] [blame] | 191 | {{- if .Values.global.migration.enabled }} |
| 192 | - name: backup-storage |
| 193 | persistentVolumeClaim: |
| 194 | claimName: {{ include "common.fullname" . }}-migration |
| 195 | {{- end }} |
| 196 | restartPolicy: Never |
| 197 | imagePullSecrets: |
| 198 | - name: "{{ include "common.namespace" . }}-docker-registry-key" |