From 97da3c59da64b6c6ead37c072493051915e7f7a3 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 25 Feb 2019 23:10:50 +0000 Subject: [PATCH] Use helm-toolkit for DB initialization Depends-On: https://review.openstack.org/#/c/635348/ Change-Id: Ie9328755d1cb2f27bfa83c0f5a6568c97befe9bf --- charts/deckhand/templates/bin/_db-init.sh.tpl | 43 ------------------- charts/deckhand/templates/configmap-bin.yaml | 4 +- charts/deckhand/templates/job-db-init.yaml | 13 ++---- 3 files changed, 6 insertions(+), 54 deletions(-) delete mode 100644 charts/deckhand/templates/bin/_db-init.sh.tpl 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 4f900acb..00000000 --- a/charts/deckhand/templates/bin/_db-init.sh.tpl +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -{{/* -Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - -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. -*/}} - -set -ex -export HOME=/tmp - -pgsql_superuser_cmd () { - DB_COMMAND="$1" - if [[ ! -z $2 ]]; then - EXPORT PGDATABASE=$2 - fi - - psql \ - -h ${DB_FQDN} \ - -p ${DB_PORT} \ - -U ${DB_ADMIN_USER} \ - --command="${DB_COMMAND}" -} - -# Create db -pgsql_superuser_cmd "SELECT 1 FROM pg_database WHERE datname = '$DB_NAME'" | grep -q 1 || pgsql_superuser_cmd "CREATE DATABASE $DB_NAME" - -# Create db user -pgsql_superuser_cmd "SELECT * FROM pg_roles WHERE rolname = '$DB_SERVICE_USER';" | tail -n +3 | head -n -2 | grep -q 1 || \ - pgsql_superuser_cmd "CREATE ROLE ${DB_SERVICE_USER} LOGIN PASSWORD '$DB_SERVICE_PASSWORD';" - -# Grant permissions to user -pgsql_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 4b9e357d..35188d20 100644 --- a/charts/deckhand/templates/configmap-bin.yaml +++ b/charts/deckhand/templates/configmap-bin.yaml @@ -28,7 +28,7 @@ data: ks-domain-user.sh: | {{- include "helm-toolkit.scripts.keystone_domain_user" . | indent 4 }} db-init.sh: |+ -{{ tuple "bin/_db-init.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} +{{- include "helm-toolkit.scripts.pg_db_init" . | indent 4 }} db-sync.sh: |+ {{ tuple "bin/_db-sync.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/deckhand/templates/job-db-init.yaml b/charts/deckhand/templates/job-db-init.yaml index 29864792..5646f073 100644 --- a/charts/deckhand/templates/job-db-init.yaml +++ b/charts/deckhand/templates/job-db-init.yaml @@ -45,27 +45,22 @@ spec: imagePullPolicy: {{ .Values.images.pull_policy | quote }} {{ tuple $envAll $envAll.Values.pod.resources.jobs.db_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} env: - - name: DECKHAND_DB_URL - valueFrom: - secretKeyRef: - name: {{ .Values.secrets.postgresql.user }} - key: DATABASE_URI - - name: DB_NAME + - name: USER_DB_NAME valueFrom: secretKeyRef: name: {{ .Values.secrets.postgresql.user }} key: DATABASE_NAME - - name: DB_SERVICE_USER + - name: USER_DB_USER valueFrom: secretKeyRef: name: {{ .Values.secrets.postgresql.user }} key: DATABASE_USERNAME - - name: DB_SERVICE_PASSWORD + - name: USER_DB_PASS valueFrom: secretKeyRef: name: {{ .Values.secrets.postgresql.user }} key: DATABASE_PASSWORD - - name: DB_FQDN + - name: DB_HOST valueFrom: secretKeyRef: name: {{ .Values.secrets.postgresql.user }}