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