From 7894eeb964c2ed81bd744c28850d334e11998c48 Mon Sep 17 00:00:00 2001 From: okozachenko Date: Thu, 30 Jul 2020 19:39:07 +0300 Subject: [PATCH] Add backup for mysqlCluster Change-Id: Ia7b7fb413566632a6b443df2f136ec5017d3247f --- chart/test-values.yaml | 3 ++ config/samples/operator-config.yaml | 3 ++ openstack_operator/operator.py | 39 +++++++++++++++---- .../mysqlcluster/mysqlcluster.yml.j2 | 4 ++ openstack_operator/utils.py | 24 ++++++++++++ 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/chart/test-values.yaml b/chart/test-values.yaml index 10d7d0bd..836f34e6 100644 --- a/chart/test-values.yaml +++ b/chart/test-values.yaml @@ -29,3 +29,6 @@ configMap: mysql: size: 10Gi chronyd: {} + backup: + secretName: aws-backup + url: s3://backups/ diff --git a/config/samples/operator-config.yaml b/config/samples/operator-config.yaml index eba1a805..01e1e12c 100644 --- a/config/samples/operator-config.yaml +++ b/config/samples/operator-config.yaml @@ -15,3 +15,6 @@ data: glance: dataDir: /opt/stack/data/glance chronyd: {} + backup: + secretName: aws-backup + url: s3://backups/ \ No newline at end of file diff --git a/openstack_operator/operator.py b/openstack_operator/operator.py index 84069ae1..a99c2066 100644 --- a/openstack_operator/operator.py +++ b/openstack_operator/operator.py @@ -58,18 +58,23 @@ def deploy(name, namespace, new, **_): config = utils.to_dict(new['data']['operator-config.yaml']) if "keystone" in config: - keystone.create_or_resume("keystone", config["keystone"]) + spec = set_service_config(config, "keystone") + keystone.create_or_resume("keystone", spec) if "horizon" in config: - horizon.create_secret("horizon") - horizon.create_or_resume("horizon", config["horizon"]) + spec = set_service_config(config, "horizon") + horizon.create_or_resume("horizon", spec) if "heat" in config: - heat.create_or_resume("heat", config["heat"]) + spec = set_service_config(config, "heat") + heat.create_or_resume("heat", spec) if "glance" in config: - glance.create_or_resume("glance", config["glance"]) + spec = set_service_config(config, "glance") + glance.create_or_resume("glance", spec) if "magnum" in config: - magnum.create_or_resume("magnum", config["magnum"]) + spec = set_service_config(config, "magnum") + magnum.create_or_resume("magnum", spec) if "ceilometer" in config: - ceilometer.create_or_resume(config["ceilometer"]) + spec = config["ceilometer"] + ceilometer.create_or_resume(spec) if "chronyd" in config: spec = config["chronyd"] @@ -82,3 +87,23 @@ def deploy(name, namespace, new, **_): else: spec = {} libvirtd_exporter.create_or_resume(spec) + + +def set_service_config(all_config, service_name): + """Retrieve the config for each openstack service + + The config for each service is comprised of service-level + config and operator-level config""" + + # Set the service level config + spec = 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 "mysql" in spec: + spec["mysql"].update(all_config["backup"]) + else: + spec["mysql"] = all_config["backup"] + + return spec diff --git a/openstack_operator/templates/mysqlcluster/mysqlcluster.yml.j2 b/openstack_operator/templates/mysqlcluster/mysqlcluster.yml.j2 index 9eb98dd0..44b87cc4 100644 --- a/openstack_operator/templates/mysqlcluster/mysqlcluster.yml.j2 +++ b/openstack_operator/templates/mysqlcluster/mysqlcluster.yml.j2 @@ -22,6 +22,10 @@ metadata: {{ labels(name) | indent(4) }} spec: replicas: 2 + backupSchedule: {{ spec.schedule }} + backupScheduleJobsHistoryLimit: 6 + backupSecretName: {{ spec.secretName }} + backupURL: {{ spec.url }} secretName: {{ name }}-mysql {% if "mysqlConf" in spec %} mysqlConf: diff --git a/openstack_operator/utils.py b/openstack_operator/utils.py index 147487e4..61f55f57 100644 --- a/openstack_operator/utils.py +++ b/openstack_operator/utils.py @@ -35,6 +35,19 @@ import openstack from openstack_operator import objects +BACKUP_SCHEDULE = { + 'magnum': '0 0 * * * *', + 'barbican': '0 5 * * * *', + 'cinder': '0 10 * * * *', + 'glance': '0 15 * * * *', + 'heat': '0 20 * * * *', + 'neutron': '0 25 * * * *', + 'octavia': '0 30 * * * *', + 'nova': '0 35 * * * *', + 'keystone': '0 40 * * * *', + 'zuul': '0 58 * * * *' +} + DIR_PATH = os.path.dirname(os.path.realpath(__file__)) VERSION = version.VersionInfo('openstack_operator').version_string() @@ -261,3 +274,14 @@ def get_configmap(namespace, name): return None return config.obj["data"] + + +def get_backup_schedule(name): + """Retrieve backup schedule for openstack services + + This function retrieves a backup schedule for the specified openstack + service and the schedule is a cronjob format""" + + if name not in BACKUP_SCHEDULE: + return "0 0 * * * *" + return BACKUP_SCHEDULE[name]