Browse Source

Use helm-toolkit for DB initialization

Depends-On: https://review.openstack.org/#/c/635348/
Change-Id: Ie9328755d1cb2f27bfa83c0f5a6568c97befe9bf
changes/18/639218/2
Nishant Kumar 3 months ago
parent
commit
97da3c59da

+ 0
- 43
charts/deckhand/templates/bin/_db-init.sh.tpl View File

@@ -1,43 +0,0 @@
1
-#!/bin/bash
2
-
3
-{{/*
4
-Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5
-
6
-Licensed under the Apache License, Version 2.0 (the "License");
7
-you may not use this file except in compliance with the License.
8
-You may obtain a copy of the License at
9
-
10
-   http://www.apache.org/licenses/LICENSE-2.0
11
-
12
-Unless required by applicable law or agreed to in writing, software
13
-distributed under the License is distributed on an "AS IS" BASIS,
14
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
-See the License for the specific language governing permissions and
16
-limitations under the License.
17
-*/}}
18
-
19
-set -ex
20
-export HOME=/tmp
21
-
22
-pgsql_superuser_cmd () {
23
-  DB_COMMAND="$1"
24
-  if [[ ! -z $2 ]]; then
25
-      EXPORT PGDATABASE=$2
26
-  fi
27
-
28
-  psql \
29
-  -h ${DB_FQDN} \
30
-  -p ${DB_PORT} \
31
-  -U ${DB_ADMIN_USER} \
32
-  --command="${DB_COMMAND}"
33
-}
34
-
35
-# Create db
36
-pgsql_superuser_cmd "SELECT 1 FROM pg_database WHERE datname = '$DB_NAME'" | grep -q 1 || pgsql_superuser_cmd "CREATE DATABASE $DB_NAME"
37
-
38
-# Create db user
39
-pgsql_superuser_cmd "SELECT * FROM pg_roles WHERE rolname = '$DB_SERVICE_USER';" | tail -n +3 | head -n -2 | grep -q 1 || \
40
-    pgsql_superuser_cmd "CREATE ROLE ${DB_SERVICE_USER} LOGIN PASSWORD '$DB_SERVICE_PASSWORD';"
41
-
42
-# Grant permissions to user
43
-pgsql_superuser_cmd "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME to $DB_SERVICE_USER;"

+ 2
- 2
charts/deckhand/templates/configmap-bin.yaml View File

@@ -28,7 +28,7 @@ data:
28 28
   ks-domain-user.sh: |
29 29
 {{- include "helm-toolkit.scripts.keystone_domain_user" . | indent 4 }}
30 30
   db-init.sh: |+
31
-{{ tuple "bin/_db-init.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
31
+{{- include "helm-toolkit.scripts.pg_db_init" . | indent 4 }}
32 32
   db-sync.sh: |+
33 33
 {{ tuple "bin/_db-sync.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
34
-{{- end }}
34
+{{- end }}

+ 4
- 9
charts/deckhand/templates/job-db-init.yaml View File

@@ -45,27 +45,22 @@ spec:
45 45
           imagePullPolicy: {{ .Values.images.pull_policy | quote }}
46 46
 {{ tuple $envAll $envAll.Values.pod.resources.jobs.db_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
47 47
           env:
48
-            - name: DECKHAND_DB_URL
49
-              valueFrom:
50
-                secretKeyRef:
51
-                  name: {{ .Values.secrets.postgresql.user }}
52
-                  key: DATABASE_URI
53
-            - name: DB_NAME
48
+            - name: USER_DB_NAME
54 49
               valueFrom:
55 50
                 secretKeyRef:
56 51
                   name: {{ .Values.secrets.postgresql.user }}
57 52
                   key: DATABASE_NAME
58
-            - name: DB_SERVICE_USER
53
+            - name: USER_DB_USER
59 54
               valueFrom:
60 55
                 secretKeyRef:
61 56
                   name: {{ .Values.secrets.postgresql.user }}
62 57
                   key: DATABASE_USERNAME
63
-            - name: DB_SERVICE_PASSWORD
58
+            - name: USER_DB_PASS
64 59
               valueFrom:
65 60
                 secretKeyRef:
66 61
                   name: {{ .Values.secrets.postgresql.user }}
67 62
                   key: DATABASE_PASSWORD
68
-            - name: DB_FQDN
63
+            - name: DB_HOST
69 64
               valueFrom:
70 65
                 secretKeyRef:
71 66
                   name: {{ .Values.secrets.postgresql.user }}

Loading…
Cancel
Save