Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions cinder/templates/bin/_db-init.sh.tpl

This file was deleted.

4 changes: 2 additions & 2 deletions cinder/templates/configmap-bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ kind: ConfigMap
metadata:
name: cinder-bin
data:
db-init.sh: |+
{{ tuple "bin/_db-init.sh.tpl" . | include "template" | indent 4 }}
db-create.py: |
{{- include "job_create_db" . | indent 4 }}
ks-service.sh: |+
{{- include "common_keystone_service" . | indent 4 }}
ks-endpoints.sh: |+
Expand Down
42 changes: 31 additions & 11 deletions cinder/templates/job-db-init.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $envAll := . }}
{{- $dependencies := .Values.dependencies.db_init }}
{{- $dependencies := .Values.dependencies.init }}
apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -17,20 +17,40 @@ spec:
{{ .Values.labels.node_selector_key }}: {{ .Values.labels.node_selector_value }}
containers:
- name: cinder-db-init
image: {{ .Values.images.db_init | quote }}
imagePullPolicy: {{ .Values.images.pull_policy | quote }}
image: {{ .Values.images.db_init }}
imagePullPolicy: {{ .Values.images.pull_policy }}
env:
- name: ANSIBLE_LIBRARY
value: /usr/share/ansible/
- name: ROOT_DB_CONNECTION
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret.root }}
key: DB_CONNECTION
- name: OPENSTACK_CONFIG_FILE
value: /etc/cinder/cinder.conf
- name: OPENSTACK_CONFIG_DB_SECTION
value: database
- name: OPENSTACK_CONFIG_DB_KEY
value: connection
command:
- bash
- /tmp/db-init.sh
- python
- /tmp/db-create.py
volumeMounts:
- name: dbinitsh
mountPath: /tmp/db-init.sh
subPath: db-init.sh
- name: configmap-bin
mountPath: /tmp/db-create.py
subPath: db-create.py
readOnly: true
- name: pod-etc-service
mountPath: /etc/cinder
- name: service-config
mountPath: /etc/cinder/cinder.conf
subPath: cinder.conf
readOnly: true
volumes:
- name: dbinitsh
- name: configmap-bin
configMap:
name: cinder-bin
- name: pod-etc-service
emptyDir: {}
- name: service-config
configMap:
name: cinder-etc
9 changes: 9 additions & 0 deletions cinder/templates/secret-db-root.env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- $dbRootConnection := printf "mysql+pymysql://%s:%s@%s:%1.f" .Values.database.root_user .Values.database.root_password .Values.database.address .Values.database.port }}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.database.secret.root }}
type: Opaque
data:
DB_CONNECTION: |
{{ $dbRootConnection | b64enc | indent 4 }}
4 changes: 3 additions & 1 deletion cinder/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ images:
ks_user: quay.io/stackanetes/stackanetes-kolla-toolbox:newton
ks_service: quay.io/stackanetes/stackanetes-kolla-toolbox:newton
ks_endpoints: quay.io/stackanetes/stackanetes-kolla-toolbox:newton
db_init: quay.io/stackanetes/stackanetes-kolla-toolbox:newton
db_init: quay.io/stackanetes/stackanetes-cinder-api:newton
db_sync: quay.io/stackanetes/stackanetes-cinder-api:newton
api: quay.io/stackanetes/stackanetes-cinder-api:newton
scheduler: quay.io/stackanetes/stackanetes-cinder-scheduler:newton
Expand Down Expand Up @@ -56,6 +56,8 @@ service:
proto: "http"

database:
secret:
root: cinder-db-root
address: mariadb
port: 3306
root_user: root
Expand Down
116 changes: 116 additions & 0 deletions common/templates/scripts/_job-create-db.py.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{{- define "job_create_db" }}
#!/usr/bin/env python

# Copyright 2017 Pete Birley
#
# 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.

# Creates db and user for an OpenStack Service:
# Set ROOT_DB_CONNECTION and DB_CONNECTION environment variables to contain
# SQLAlchemy strings for the root connection to the database and the one you
# wish the service to use. Alternatively, you can use an ini formatted config
# at the location specified by OPENSTACK_CONFIG_FILE, and extract the string
# from the key OPENSTACK_CONFIG_DB_KEY, in the section specified by
# OPENSTACK_CONFIG_DB_SECTION.

import os
import sys
import ConfigParser
from sqlalchemy import create_engine

# Get the connection string for the service db root user
if "ROOT_DB_CONNECTION" in os.environ:
db_connection = os.environ['ROOT_DB_CONNECTION']
else:
print 'ROOT_DB_CONNECTION env var missing'
sys.exit(1)

# Get the connection string for the service db
if "OPENSTACK_CONFIG_FILE" in os.environ:
try:
os_conf = os.environ['OPENSTACK_CONFIG_FILE']
if "OPENSTACK_CONFIG_DB_SECTION" in os.environ:
os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION']
else:
print 'Env var OPENSTACK_CONFIG_DB_SECTION not set'
sys.exit(1)
if "OPENSTACK_CONFIG_DB_KEY" in os.environ:
os_conf_key = os.environ['OPENSTACK_CONFIG_DB_KEY']
else:
print 'Env var OPENSTACK_CONFIG_DB_KEY not set'
sys.exit(1)
config = ConfigParser.RawConfigParser()
print("Using {0} as db config source".format(os_conf))
config.read(os_conf)
print("Trying to load db config from {0}:{1}".format(
os_conf_section, os_conf_key))
user_db_conn = config.get(os_conf_section, os_conf_key)
print("Got config from {0}".format(os_conf))
except:
print("Tried to load config from {0} but failed.".format(os_conf))
sys.exit(1)
elif "DB_CONNECTION" in os.environ:
user_db_conn = os.environ['DB_CONNECTION']
print 'Got config from DB_CONNECTION env var'
else:
print 'Could not get db config, either from config file or env var'
sys.exit(1)

# Root DB engine
try:
root_engine = create_engine(db_connection)
connection = root_engine.connect()
connection.close()
except:
print 'Could not connect to database as root user'
sys.exit(1)

# User DB engine
try:
user_engine = create_engine(user_db_conn)
# Get our user data out of the user_engine
database = user_engine.url.database
user = user_engine.url.username
password = user_engine.url.password
print 'Got user db config'
except:
print 'Could not get user database config'
sys.exit(1)

# Create DB
try:
root_engine.execute("CREATE DATABASE IF NOT EXISTS {0}".format(database))
print("Created database {0}".format(database))
except:
print("Could not create database {0}".format(database))
sys.exit(1)

# Create DB User
try:
root_engine.execute(
"GRANT ALL ON `{0}`.* TO \'{1}\'@\'%%\' IDENTIFIED BY \'{2}\'".format(
database, user, password))
print("Created user {0} for {1}".format(user, database))
except:
print("Could not create user {0} for {1}".format(user, database))
sys.exit(1)

# Test connection
try:
connection = user_engine.connect()
connection.close()
print 'Database connection for user ok'
except:
print 'Could not connect to database as user'
sys.exit(1)
{{- end }}
17 changes: 0 additions & 17 deletions glance/templates/bin/_init.sh.tpl

This file was deleted.

4 changes: 2 additions & 2 deletions glance/templates/configmap-bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: ConfigMap
metadata:
name: glance-bin
data:
init.sh: |+
{{ tuple "bin/_init.sh.tpl" . | include "template" | indent 4 }}
db-create.py: |
{{- include "job_create_db" . | indent 4 }}
post.sh: |+
{{ tuple "bin/_post.sh.tpl" . | include "template" | indent 4 }}
37 changes: 29 additions & 8 deletions glance/templates/job-db-init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,37 @@ spec:
image: {{ .Values.images.db_init }}
imagePullPolicy: {{ .Values.images.pull_policy }}
env:
- name: ANSIBLE_LIBRARY
value: /usr/share/ansible/
- name: ROOT_DB_CONNECTION
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret.root }}
key: DB_CONNECTION
- name: OPENSTACK_CONFIG_FILE
value: /etc/glance/glance-api.conf
- name: OPENSTACK_CONFIG_DB_SECTION
value: database
- name: OPENSTACK_CONFIG_DB_KEY
value: connection
command:
- bash
- /tmp/init.sh
- python
- /tmp/db-create.py
volumeMounts:
- name: initsh
mountPath: /tmp/init.sh
subPath: init.sh
- name: configmap-bin
mountPath: /tmp/db-create.py
subPath: db-create.py
readOnly: true
- name: pod-etc-service
mountPath: /etc/glance
- name: service-config
mountPath: /etc/glance/glance-api.conf
subPath: glance-api.conf
readOnly: true
volumes:
- name: initsh
- name: configmap-bin
configMap:
name: glance-bin
- name: pod-etc-service
emptyDir: {}
- name: service-config
configMap:
name: glance-etc
9 changes: 9 additions & 0 deletions glance/templates/secret-db-root.env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- $dbRootConnection := printf "mysql+pymysql://%s:%s@%s:%1.f" .Values.database.root_user .Values.database.root_password .Values.database.address .Values.database.port }}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.database.secret.root }}
type: Opaque
data:
DB_CONNECTION: |
{{ $dbRootConnection | b64enc | indent 4 }}
4 changes: 3 additions & 1 deletion glance/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ labels:
node_selector_value: enabled

images:
db_init: quay.io/stackanetes/stackanetes-kolla-toolbox:newton
db_init: quay.io/stackanetes/stackanetes-glance-api:newton
db_sync: quay.io/stackanetes/stackanetes-glance-api:newton
api: quay.io/stackanetes/stackanetes-glance-api:newton
registry: quay.io/stackanetes/stackanetes-glance-registry:newton
Expand Down Expand Up @@ -50,6 +50,8 @@ network:
ip_address: "0.0.0.0"

database:
secret:
root: glance-db-root
address: mariadb
port: 3306
root_user: root
Expand Down
21 changes: 0 additions & 21 deletions heat/templates/bin/_db-init.sh.tpl

This file was deleted.

4 changes: 2 additions & 2 deletions heat/templates/configmap-bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ kind: ConfigMap
metadata:
name: heat-bin
data:
db-init.sh: |+
{{ tuple "bin/_db-init.sh.tpl" . | include "template" | indent 4 }}
db-create.py: |
{{- include "job_create_db" . | indent 4 }}
ks-service.sh: |+
{{- include "common_keystone_service" . | indent 4 }}
ks-endpoints.sh: |+
Expand Down
Loading