Browse Source

Use helm toolkit for DB initialization

Depends-On: https://review.openstack.org/#/c/635348/

Change-Id: I55fa7a08b919581552dd512316fc42581762a6a4
changes/25/634625/12
Nishant Kumar 3 months ago
parent
commit
ebe95d1875

+ 0
- 43
charts/drydock/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;"

+ 1
- 1
charts/drydock/templates/configmap-bin.yaml View File

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

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

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

+ 1
- 1
tools/helm_tk.sh View File

@@ -18,7 +18,7 @@
18 18
 HELM=$1
19 19
 HTK_REPO=${HTK_REPO:-"https://github.com/openstack/openstack-helm-infra"}
20 20
 HTK_PATH=${HTK_PATH:-""}
21
-HTK_STABLE_COMMIT=${HTK_COMMIT:-"42249d4243d892b7d04ce6aed9b0c8d7edcbfc7a"}
21
+HTK_STABLE_COMMIT=${HTK_COMMIT:-"7f21b85128ea4e6e64998b916f065c3100f5c4f7"}
22 22
 DEP_UP_LIST=${DEP_UP_LIST:-"drydock"}
23 23
 BUILD_DIR=${BUILD_DIR:-$(mktemp -d)}
24 24
 

Loading…
Cancel
Save