summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Kumar <nk613n@att.com>2019-02-04 04:56:51 +0000
committerNishant Kumar <nk613n@att.com>2019-03-04 18:02:37 +0000
commitebe95d18756f1e35a0e36c18078a07b823b861f0 (patch)
tree8b39dc0a1a072608868fca55bdc135369059f1f9
parent7504c2f907276ce4cc6e48c74755f3f9a9b4159c (diff)
Use helm toolkit for DB initialization
Depends-On: https://review.openstack.org/#/c/635348/ Change-Id: I55fa7a08b919581552dd512316fc42581762a6a4
Notes
Notes (review): Code-Review+2: Scott Hussey <sthussey@att.com> Code-Review+1: Drew Walters <drewwalters96@gmail.com> Code-Review+2: Sean Eagan <sean.eagan@att.com> Workflow+1: Sean Eagan <sean.eagan@att.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 05 Mar 2019 20:46:21 +0000 Reviewed-on: https://review.openstack.org/634625 Project: openstack/airship-drydock Branch: refs/heads/master
-rw-r--r--charts/drydock/templates/bin/_db-init.sh.tpl43
-rwxr-xr-xcharts/drydock/templates/configmap-bin.yaml2
-rw-r--r--charts/drydock/templates/job-drydock-db-init.yaml8
-rwxr-xr-xtools/helm_tk.sh2
4 files changed, 6 insertions, 49 deletions
diff --git a/charts/drydock/templates/bin/_db-init.sh.tpl b/charts/drydock/templates/bin/_db-init.sh.tpl
deleted file mode 100644
index f48d043..0000000
--- a/charts/drydock/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/drydock/templates/configmap-bin.yaml b/charts/drydock/templates/configmap-bin.yaml
index c7b5293..c6b1f74 100755
--- a/charts/drydock/templates/configmap-bin.yaml
+++ b/charts/drydock/templates/configmap-bin.yaml
@@ -29,7 +29,7 @@ data:
29 ks-domain-user.sh: | 29 ks-domain-user.sh: |
30{{- include "helm-toolkit.scripts.keystone_domain_user" . | indent 4 }} 30{{- include "helm-toolkit.scripts.keystone_domain_user" . | indent 4 }}
31 db-init.sh: |+ 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 db-sync.sh: |+ 33 db-sync.sh: |+
34{{ tuple "bin/_db-sync.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} 34{{ tuple "bin/_db-sync.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
35... 35...
diff --git a/charts/drydock/templates/job-drydock-db-init.yaml b/charts/drydock/templates/job-drydock-db-init.yaml
index 0550361..6d97609 100644
--- a/charts/drydock/templates/job-drydock-db-init.yaml
+++ b/charts/drydock/templates/job-drydock-db-init.yaml
@@ -43,22 +43,22 @@ spec:
43 imagePullPolicy: {{ .Values.images.pull_policy | quote }} 43 imagePullPolicy: {{ .Values.images.pull_policy | quote }}
44{{ tuple $envAll $envAll.Values.pod.resources.jobs.drydock_db_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} 44{{ tuple $envAll $envAll.Values.pod.resources.jobs.drydock_db_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
45 env: 45 env:
46 - name: DB_NAME 46 - name: USER_DB_NAME
47 valueFrom: 47 valueFrom:
48 secretKeyRef: 48 secretKeyRef:
49 name: {{ .Values.secrets.postgresql.user }} 49 name: {{ .Values.secrets.postgresql.user }}
50 key: DATABASE_NAME 50 key: DATABASE_NAME
51 - name: DB_SERVICE_USER 51 - name: USER_DB_USER
52 valueFrom: 52 valueFrom:
53 secretKeyRef: 53 secretKeyRef:
54 name: {{ .Values.secrets.postgresql.user }} 54 name: {{ .Values.secrets.postgresql.user }}
55 key: DATABASE_USERNAME 55 key: DATABASE_USERNAME
56 - name: DB_SERVICE_PASSWORD 56 - name: USER_DB_PASS
57 valueFrom: 57 valueFrom:
58 secretKeyRef: 58 secretKeyRef:
59 name: {{ .Values.secrets.postgresql.user }} 59 name: {{ .Values.secrets.postgresql.user }}
60 key: DATABASE_PASSWORD 60 key: DATABASE_PASSWORD
61 - name: DB_FQDN 61 - name: DB_HOST
62 valueFrom: 62 valueFrom:
63 secretKeyRef: 63 secretKeyRef:
64 name: {{ .Values.secrets.postgresql.user }} 64 name: {{ .Values.secrets.postgresql.user }}
diff --git a/tools/helm_tk.sh b/tools/helm_tk.sh
index b8d2fe0..c5d2a8e 100755
--- a/tools/helm_tk.sh
+++ b/tools/helm_tk.sh
@@ -18,7 +18,7 @@
18HELM=$1 18HELM=$1
19HTK_REPO=${HTK_REPO:-"https://github.com/openstack/openstack-helm-infra"} 19HTK_REPO=${HTK_REPO:-"https://github.com/openstack/openstack-helm-infra"}
20HTK_PATH=${HTK_PATH:-""} 20HTK_PATH=${HTK_PATH:-""}
21HTK_STABLE_COMMIT=${HTK_COMMIT:-"42249d4243d892b7d04ce6aed9b0c8d7edcbfc7a"} 21HTK_STABLE_COMMIT=${HTK_COMMIT:-"7f21b85128ea4e6e64998b916f065c3100f5c4f7"}
22DEP_UP_LIST=${DEP_UP_LIST:-"drydock"} 22DEP_UP_LIST=${DEP_UP_LIST:-"drydock"}
23BUILD_DIR=${BUILD_DIR:-$(mktemp -d)} 23BUILD_DIR=${BUILD_DIR:-$(mktemp -d)}
24 24