in mysqloperator/init_main.py [0:0]
def init_meb_restore(pod: MySQLPod, cluster: InnoDBCluster, logger: logging.Logger):
"""Check whether the restore container should restore or not
The restore container is based on MySQL Server, not Operator, thus has no
access to Kubernetes API etc. in here we make the decision whether this
is the first pod of a fresh InnoDB Cluster (i.e. not a recreated -0 for
an otherwise running cluster) and leave a marker.
We also use tha API to fetch Secrets with credentials for restoring the
backup, so that Secret may be deleted afterward"""
# Remove Marker as safe fallback
try:
os.remove('/tmp/meb_restore.json')
except FileNotFoundError:
# no problem if the file doesn't exist, this would still raise when
# failing to remove for permission issues etc which shouldn't happen
pass
# Check precoditions
if not cluster.parsed_spec.initDB or not cluster.parsed_spec.initDB.meb:
logger.error("No MySQL Enterprise Restore configured.")
return
if cluster.parsed_spec.edition != config.Edition.enterprise:
print("MySQL Enterprise Restore request, but this is not Enterprise Edition")
sys.exit(1)
if pod.index:
logger.info(f"Nothing to do for restore - restore happens only on Pod 0. this is {pod.name}")
return
if cluster.get_create_time() is not None:
logger.info("Nothing to do for restore - this is a restart")
return
if pod.instance_type != "group-member":
logger.info(f"Nothing to do for restore - this is not a group member but {pod.instance_type}")
return
# All preconditions are met. We should request a restore.
logger.info("We got to request a MEB restore")
mebspec = cluster.parsed_spec.initDB.meb
if mebspec.oci_credentials:
credentials = get_secret(mebspec.oci_credentials, cluster.namespace, logger)
elif mebspec.s3_credentials:
credentials = get_secret(mebspec.s3_credentials, cluster.namespace, logger)
meb_init_spec = {
"spec": cluster.spec["initDB"]["meb"],
"credentials": credentials
}
with open('/tmp/meb_restore.json', 'w') as f:
json.dump(meb_init_spec, f)