in mysqloperator/controller/backup/backup_objects.py [0:0]
def compare_schedules(spec: InnoDBClusterSpec, old: dict, new: dict, logger: Logger) -> dict:
logger.info(f"backup_objects.compare_schedules {spec.namespace}/{spec.name}")
old_schedules = {}
if not old is None:
for old_object in old:
schedule = BackupSchedule(spec)
# Don't try to load the profile as it might not exist anymore:
# If the profile name is changed together with the schedule that references it,
# then we can't load with the old name from k8s API, as won't exist. All what exists
# is in new.
schedule.parse(old_object, "", load_profile=False)
old_schedules[schedule.name] = schedule
if old == new:
return {
'removed': {},
'added': {},
'modified': {},
'unmodified': old_schedules
}
new_schedules = {}
if not new is None:
for new_object in new:
schedule = BackupSchedule(spec)
schedule.parse(new_object, "")
new_schedules[schedule.name] = schedule
removed = {}
added = {}
modified = {}
unmodified = {}
# Check for modified, non-modified and removed objects
for old_schedule_name, old_schedule_obj in old_schedules.items():
if old_schedule_name in new_schedules:
new_schedule_obj = new_schedules[old_schedule_name]
if old_schedule_obj == new_schedule_obj:
unmodified[old_schedule_name] = old_schedule_obj
else:
modified[old_schedule_name] = { 'old' : old_schedule_obj, 'new' : new_schedule_obj}
else:
removed[old_schedule_name] = old_schedule_obj
# Now it's time to check if something was added
for new_schedule_name, new_schedule_obj in new_schedules.items():
if not (new_schedule_name in old_schedules):
added[new_schedule_name] = new_schedule_obj
return {
'removed': removed,
'added': added,
'modified': modified,
'unmodified': unmodified
}