summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Kumar <nk613n@att.com>2019-02-25 23:10:50 +0000
committerNishant Kumar <nk613n@att.com>2019-03-04 15:12:39 +0000
commit97da3c59da64b6c6ead37c072493051915e7f7a3 (patch)
tree6e306a81020699a2d3c52e51f9851e64c340c5b8
parent49ad9f38842f7f1ecb86d907d86d332f8186eb8c (diff)
Use helm-toolkit for DB initialization
Depends-On: https://review.openstack.org/#/c/635348/ Change-Id: Ie9328755d1cb2f27bfa83c0f5a6568c97befe9bf
Notes
Notes (review): Code-Review+1: Drew Walters <drewwalters96@gmail.com> Code-Review+2: Felipe Monteiro <felipe.monteiro@att.com> Code-Review+2: Scott Hussey <sthussey@att.com> Workflow+1: Scott Hussey <sthussey@att.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 05 Mar 2019 19:21:06 +0000 Reviewed-on: https://review.openstack.org/639218 Project: openstack/airship-deckhand Branch: refs/heads/master
-rw-r--r--charts/deckhand/templates/bin/_db-init.sh.tpl43
-rw-r--r--charts/deckhand/templates/configmap-bin.yaml4
-rw-r--r--charts/deckhand/templates/job-db-init.yaml13
3 files changed, 6 insertions, 54 deletions
diff --git a/charts/deckhand/templates/bin/_db-init.sh.tpl b/charts/deckhand/templates/bin/_db-init.sh.tpl
deleted file mode 100644
index 4f900ac..0000000
--- a/charts/deckhand/templates/bin/_db-init.sh.tpl
+++ /dev/null
@@ -1,43 +0,0 @@
1#!/bin/bash
2
3{{/*
4Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17*/}}
18
19set -ex
20export HOME=/tmp
21
22pgsql_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
36pgsql_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
39pgsql_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
43pgsql_superuser_cmd "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME to $DB_SERVICE_USER;"
diff --git a/charts/deckhand/templates/configmap-bin.yaml b/charts/deckhand/templates/configmap-bin.yaml
index 4b9e357..35188d2 100644
--- a/charts/deckhand/templates/configmap-bin.yaml
+++ b/charts/deckhand/templates/configmap-bin.yaml
@@ -28,7 +28,7 @@ data:
28 ks-domain-user.sh: | 28 ks-domain-user.sh: |
29{{- include "helm-toolkit.scripts.keystone_domain_user" . | indent 4 }} 29{{- include "helm-toolkit.scripts.keystone_domain_user" . | indent 4 }}
30 db-init.sh: |+ 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 db-sync.sh: |+ 32 db-sync.sh: |+
33{{ tuple "bin/_db-sync.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} 33{{ tuple "bin/_db-sync.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
34{{- end }} \ No newline at end of file 34{{- end }}
diff --git a/charts/deckhand/templates/job-db-init.yaml b/charts/deckhand/templates/job-db-init.yaml
index 2986479..5646f07 100644
--- a/charts/deckhand/templates/job-db-init.yaml
+++ b/charts/deckhand/templates/job-db-init.yaml
@@ -45,27 +45,22 @@ spec:
45 imagePullPolicy: {{ .Values.images.pull_policy | quote }} 45 imagePullPolicy: {{ .Values.images.pull_policy | quote }}
46{{ tuple $envAll $envAll.Values.pod.resources.jobs.db_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} 46{{ tuple $envAll $envAll.Values.pod.resources.jobs.db_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
47 env: 47 env:
48 - name: DECKHAND_DB_URL 48 - name: USER_DB_NAME
49 valueFrom:
50 secretKeyRef:
51 name: {{ .Values.secrets.postgresql.user }}
52 key: DATABASE_URI
53 - name: DB_NAME
54 valueFrom: 49 valueFrom:
55 secretKeyRef: 50 secretKeyRef:
56 name: {{ .Values.secrets.postgresql.user }} 51 name: {{ .Values.secrets.postgresql.user }}
57 key: DATABASE_NAME 52 key: DATABASE_NAME
58 - name: DB_SERVICE_USER 53 - name: USER_DB_USER
59 valueFrom: 54 valueFrom:
60 secretKeyRef: 55 secretKeyRef:
61 name: {{ .Values.secrets.postgresql.user }} 56 name: {{ .Values.secrets.postgresql.user }}
62 key: DATABASE_USERNAME 57 key: DATABASE_USERNAME
63 - name: DB_SERVICE_PASSWORD 58 - name: USER_DB_PASS
64 valueFrom: 59 valueFrom:
65 secretKeyRef: 60 secretKeyRef:
66 name: {{ .Values.secrets.postgresql.user }} 61 name: {{ .Values.secrets.postgresql.user }}
67 key: DATABASE_PASSWORD 62 key: DATABASE_PASSWORD
68 - name: DB_FQDN 63 - name: DB_HOST
69 valueFrom: 64 valueFrom:
70 secretKeyRef: 65 secretKeyRef:
71 name: {{ .Values.secrets.postgresql.user }} 66 name: {{ .Values.secrets.postgresql.user }}