diff --git a/openstack_operator/barbican.py b/openstack_operator/barbican.py index b5f3db2d..40ef881b 100644 --- a/openstack_operator/barbican.py +++ b/openstack_operator/barbican.py @@ -19,7 +19,6 @@ the appropriate deployments, Mcrouter, pod monitors and Prometheus rules. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -31,7 +30,7 @@ def create_or_resume(name, spec, **_): """ # deploy mysql for barbican - database.ensure_mysql_cluster("barbican", spec=spec["mysql"]) + utils.ensure_mysql_cluster("barbican", spec["mysql"]) # deploy barbican api utils.create_or_update('barbican/daemonset.yml.j2', diff --git a/openstack_operator/cinder.py b/openstack_operator/cinder.py index 070ba0bc..77bc9e87 100644 --- a/openstack_operator/cinder.py +++ b/openstack_operator/cinder.py @@ -17,7 +17,6 @@ This module maintains the operator for Cinder. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -32,7 +31,7 @@ def create_or_resume(name, spec, **_): """ # deploy mysql for cinder - database.ensure_mysql_cluster("cinder", spec=spec["mysql"]) + utils.ensure_mysql_cluster("cinder", spec=spec["mysql"]) # deploy rabbitmq utils.deploy_rabbitmq("cinder") diff --git a/openstack_operator/database.py b/openstack_operator/database.py deleted file mode 100644 index d31e12d9..00000000 --- a/openstack_operator/database.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2020 VEXXHOST, Inc. -# -# 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. - -"""database Operator - -This module contains a few common functions for database management -""" - -from openstack_operator import utils - - -def ensure_mysql_cluster(name, user=None, database=None, spec=None): - """Create or update mysql cluster""" - - if spec is None: - spec = {} - - if database is None: - database = name - if user is None: - user = database - - config = utils.get_secret("openstack", name + "-mysql") - if config is None: - root_password = utils.generate_password() - password = utils.generate_password() - utils.create_or_update('mysqlcluster/secret-mysqlcluster.yml.j2', - name=name, user=user, - database=database, password=password, - rootPassword=root_password) - config = utils.get_secret("openstack", name + "-mysql") - - config['connection'] = \ - "mysql+pymysql://%s:%s@%s-mysql-master/%s?charset=utf8" % ( - config["USER"], - config["PASSWORD"], - name, - config["DATABASE"] - ) - - utils.create_or_update('mysqlcluster/mysqlcluster.yml.j2', - server_side=False, name=name, spec=spec) - return config diff --git a/openstack_operator/glance.py b/openstack_operator/glance.py index 42ad722e..bbfa8106 100644 --- a/openstack_operator/glance.py +++ b/openstack_operator/glance.py @@ -19,7 +19,6 @@ the appropriate deployments, Mcrouter, pod monitors and Prometheus rules. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -34,7 +33,7 @@ def create_or_resume(name, spec, **_): """ # deploy mysql for glance - database.ensure_mysql_cluster("glance", spec=spec["mysql"]) + utils.ensure_mysql_cluster("glance", spec["mysql"]) # deploy glance api utils.create_or_update('glance/daemonset.yml.j2', diff --git a/openstack_operator/heat.py b/openstack_operator/heat.py index addd1c05..1805762d 100644 --- a/openstack_operator/heat.py +++ b/openstack_operator/heat.py @@ -20,7 +20,6 @@ server for the installation. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -31,7 +30,7 @@ def create_or_resume(name, spec, **_): """Create and re-sync any Heat instances """ - database.ensure_mysql_cluster("heat", spec=spec["mysql"]) + utils.ensure_mysql_cluster("heat", spec["mysql"]) # deploy rabbitmq utils.deploy_rabbitmq("heat") diff --git a/openstack_operator/keystone.py b/openstack_operator/keystone.py index a409435e..d59850e7 100644 --- a/openstack_operator/keystone.py +++ b/openstack_operator/keystone.py @@ -23,7 +23,6 @@ import kopf from cryptography import fernet -from openstack_operator import database from openstack_operator import filters from openstack_operator import utils @@ -110,7 +109,7 @@ def create_or_resume(name, spec, **_): # (TODO)Replace the current admin url # deploy mysql - db_config = database.ensure_mysql_cluster("keystone", spec=spec["mysql"]) + db_config = utils.ensure_mysql_cluster("keystone", spec["mysql"]) # deploy memcached diff --git a/openstack_operator/magnum.py b/openstack_operator/magnum.py index b3363e1e..77943396 100644 --- a/openstack_operator/magnum.py +++ b/openstack_operator/magnum.py @@ -19,7 +19,6 @@ the appropriate deployments, an instance of Memcache, RabbitMQ and a database server for the installation. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -33,7 +32,7 @@ def create_or_resume(name, spec, **_): start the service up for the first time. """ - database.ensure_mysql_cluster("magnum", spec=spec["mysql"]) + utils.ensure_mysql_cluster("magnum", spec["mysql"]) # deploy rabbitmq utils.deploy_rabbitmq("magnum") diff --git a/openstack_operator/neutron.py b/openstack_operator/neutron.py index eebeaf1e..ef7b0da6 100644 --- a/openstack_operator/neutron.py +++ b/openstack_operator/neutron.py @@ -19,7 +19,6 @@ This code takes care of doing the operations of the OpenStack Neutron API service. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -32,9 +31,7 @@ def create_or_resume(spec, **_): This function is called when a new resource is created but also when we start the service up for the first time. """ - - database.ensure_mysql_cluster("neutron", spec=spec["mysql"]) - + utils.ensure_mysql_cluster("neutron", spec["mysql"]) utils.deploy_rabbitmq("neutron") utils.create_or_update('neutron/daemonset-server.yml.j2', spec=spec) utils.create_or_update('neutron/daemonset-openvswitch-agent.yml.j2', diff --git a/openstack_operator/nova.py b/openstack_operator/nova.py index bc78a69e..fbdc25e6 100644 --- a/openstack_operator/nova.py +++ b/openstack_operator/nova.py @@ -21,7 +21,6 @@ service. import kopf -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -45,12 +44,12 @@ def create_or_resume(spec, **_): identity.ensure_application_credential(name="nova") - databases['api'] = database.ensure_mysql_cluster( + databases['api'] = utils.ensure_mysql_cluster( "nova-api", database="nova_api" ) for cell in CELLS: - databases[cell] = database.ensure_mysql_cluster( + databases[cell] = utils.ensure_mysql_cluster( "nova-%s" % cell, database="nova_%s" % cell) # NOTE(mnaser): cell0 does not need a message queue @@ -97,6 +96,6 @@ def run_database_migrations(**_): deployment and triggers a database migrations """ - cell0 = database.ensure_mysql_cluster("nova-cell0") + cell0 = utils.ensure_mysql_cluster("nova-cell0") utils.create_or_update('nova/conductor/job.yml.j2', adopt=True, cell0_db=cell0['connection']) diff --git a/openstack_operator/operator.py b/openstack_operator/operator.py index bb6939fc..47603377 100644 --- a/openstack_operator/operator.py +++ b/openstack_operator/operator.py @@ -144,7 +144,11 @@ def set_service_config(all_config, service_name): # Inject the operator level config to service level # Backup config for mysql - all_config["backup"]["schedule"] = utils.get_backup_schedule(service_name) + if "backup" in all_config: + all_config["backup"]["schedule"] = \ + utils.get_backup_schedule(service_name) + else: + all_config["backup"] = {} if "mysql" in spec: spec["mysql"].update(all_config["backup"]) else: diff --git a/openstack_operator/placement.py b/openstack_operator/placement.py index 2bb0cdb9..494deb55 100644 --- a/openstack_operator/placement.py +++ b/openstack_operator/placement.py @@ -19,7 +19,6 @@ This code takes care of doing the operations of the OpenStack Placement API service. """ -from openstack_operator import database from openstack_operator import identity from openstack_operator import utils @@ -34,7 +33,7 @@ def create_or_resume(name, spec, **_): """ # deploy mysql for placement - database.ensure_mysql_cluster("placement", spec=spec["mysql"]) + utils.ensure_mysql_cluster("placement", spec["mysql"]) # deploy placement api utils.create_or_update('placement/daemonset.yml.j2', spec=spec) diff --git a/openstack_operator/utils.py b/openstack_operator/utils.py index fb1e5b8a..0b6fc965 100644 --- a/openstack_operator/utils.py +++ b/openstack_operator/utils.py @@ -318,3 +318,37 @@ def deploy_rabbitmq(name, **_): create_or_update('operator/secret-rabbitmq.yml.j2', name=name, password=generate_password()) create_or_update('operator/rabbitmq.yml.j2', name=name) + + +def ensure_mysql_cluster(name, spec=None, user=None, database=None): + """Create or update mysql cluster""" + + if spec is None: + spec = {} + + if database is None: + database = name + if user is None: + user = database + + config = get_secret("openstack", name + "-mysql") + if config is None: + root_password = generate_password() + password = generate_password() + create_or_update('mysqlcluster/secret-mysqlcluster.yml.j2', + name=name, user=user, + database=database, password=password, + rootPassword=root_password) + config = get_secret("openstack", name + "-mysql") + + config['connection'] = \ + "mysql+pymysql://%s:%s@%s-mysql-master/%s?charset=utf8" % ( + config["USER"], + config["PASSWORD"], + name, + config["DATABASE"] + ) + + create_or_update('mysqlcluster/mysqlcluster.yml.j2', + server_side=False, name=name, spec=spec) + return config