Skip to content

Commit d2b9753

Browse files
stuggiclaude
andcommitted
Clean up GaleraRestore CRs after successful restore
After database restore completes successfully, automatically delete the GaleraRestore CRs to clean up restore pods and free resources. Changes: - Ansible playbook: Delete GaleraRestore CRs after automated restore - Documentation: Add cleanup step (step 3) after manual restore - Helper script: Add optional delete-cr parameter (default: yes) Automated mode (Ansible playbook): - Deletes GaleraRestore CRs automatically after successful restore - Restore pods will terminate - Clean state for resumed deployment Manual mode: - Documentation shows cleanup commands - Helper script can optionally preserve CR with "no" parameter Example: ./restore-galera-latest.sh openstackrestore # Deletes CR ./restore-galera-latest.sh openstackrestore openstack no # Keeps CR This prevents unnecessary resource consumption from restore pods after the restore operation completes. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 7348494 commit d2b9753

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

docs/dev/backup-restore-ctlplane.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,21 @@ oc exec -n openstack openstack-restore-openstackrestorecell1 -- \
16161616

16171617
The restore script automatically handles both the database dump and grants file.
16181618

1619+
**3. Clean up GaleraRestore CRs:**
1620+
1621+
After successful restore, delete the GaleraRestore CRs to stop the restore pods:
1622+
1623+
```bash
1624+
# Delete GaleraRestore CRs (automatically done in Ansible playbook)
1625+
oc delete galerarestore openstackrestore -n openstack
1626+
oc delete galerarestore openstackrestorecell1 -n openstack
1627+
1628+
# Or delete all at once
1629+
oc delete galerarestore --all -n openstack
1630+
```
1631+
1632+
The restore pods will terminate once the CRs are deleted.
1633+
16191634
**Future enhancement**: See [README.md#galera-backup-timestamp-tracking](README.md#galera-backup-timestamp-tracking) for proposed solution to timestamp tracking.
16201635

16211636
After Galera database restore is complete, proceed to the next step.

docs/dev/playbooks/restore-openstack-ctlplane.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,22 @@
11261126
msg: "✓ All database restores completed ({{ galerabackup_names.stdout_lines | length }} instance(s))"
11271127
when: automated_db_restore and galerabackup_backup_file.stat.exists and galerabackup_names.stdout_lines | length > 0
11281128

1129+
- name: Cleanup GaleraRestore CRs after successful restore
1130+
ansible.builtin.shell: |
1131+
RESTORE_NAME="{{ item }}restore"
1132+
echo "Deleting GaleraRestore CR: ${RESTORE_NAME}"
1133+
oc delete galerarestore "${RESTORE_NAME}" -n {{ openstack_namespace }} --ignore-not-found=true
1134+
args:
1135+
executable: /bin/bash
1136+
loop: "{{ galerabackup_names.stdout_lines }}"
1137+
changed_when: true
1138+
when: automated_db_restore and galerabackup_backup_file.stat.exists and galerabackup_names.stdout_lines | length > 0
1139+
1140+
- name: Print GaleraRestore cleanup status
1141+
ansible.builtin.debug:
1142+
msg: "✓ GaleraRestore CRs deleted (restore pods will terminate)"
1143+
when: automated_db_restore and galerabackup_backup_file.stat.exists and galerabackup_names.stdout_lines | length > 0
1144+
11291145
- name: Confirm database restore completion (manual mode)
11301146
ansible.builtin.pause:
11311147
prompt: |

docs/dev/scripts/restore-galera-latest.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set -e
1414
# Configuration
1515
RESTORE_NAME="${1}"
1616
OPENSTACK_NAMESPACE="${2:-openstack}"
17+
DELETE_CR="${3:-yes}" # Delete GaleraRestore CR after successful restore (yes/no)
1718

1819
# Colors for output
1920
RED='\033[0;31m'
@@ -51,11 +52,17 @@ if [ -z "$RESTORE_NAME" ]; then
5152
print_error "Restore name is required"
5253
echo ""
5354
echo "Usage:"
54-
echo " $0 <restore-name> [namespace]"
55+
echo " $0 <restore-name> [namespace] [delete-cr]"
56+
echo ""
57+
echo "Arguments:"
58+
echo " restore-name - Name of the GaleraRestore CR (e.g., openstackrestore)"
59+
echo " namespace - OpenStack namespace (default: openstack)"
60+
echo " delete-cr - Delete GaleraRestore CR after successful restore (default: yes)"
5561
echo ""
5662
echo "Examples:"
5763
echo " $0 openstackrestore"
5864
echo " $0 openstackrestorecell1 openstack"
65+
echo " $0 openstackrestore openstack no # Keep GaleraRestore CR"
5966
exit 1
6067
fi
6168

@@ -162,6 +169,23 @@ if [ $RESTORE_EXIT_CODE -eq 0 ]; then
162169
print_header "Restore Completed Successfully"
163170
print_success "Database restored from: $LATEST_BACKUP"
164171
print_success "Timestamp: $TIMESTAMP"
172+
173+
# Clean up GaleraRestore CR if requested
174+
if [ "$DELETE_CR" == "yes" ]; then
175+
echo ""
176+
print_info "Cleaning up GaleraRestore CR..."
177+
if oc delete galerarestore "$RESTORE_NAME" -n "$OPENSTACK_NAMESPACE" --ignore-not-found=true; then
178+
print_success "GaleraRestore CR deleted: $RESTORE_NAME"
179+
print_info "Restore pod will terminate"
180+
else
181+
print_warning "Failed to delete GaleraRestore CR: $RESTORE_NAME"
182+
fi
183+
else
184+
echo ""
185+
print_info "GaleraRestore CR preserved (delete-cr=no)"
186+
print_info "To delete manually:"
187+
print_info " oc delete galerarestore $RESTORE_NAME -n $OPENSTACK_NAMESPACE"
188+
fi
165189
else
166190
print_header "Restore Failed"
167191
print_error "restore_galera exited with code: $RESTORE_EXIT_CODE"

0 commit comments

Comments
 (0)