Skip to content

Commit b5f3421

Browse files
stuggiclaude
andcommitted
Add ownerReference removal to all OADP restore operations
Use OADP resourceModifiers to strip ownerReferences from ALL resources during restore. This prevents orphaned resources caused by UID mismatches between backed-up ownerReferences (old UIDs) and restored owners (new UIDs). The Problem: - Every restored resource gets a NEW UID (cluster-unique) - Backed-up ownerReferences contain OLD UIDs from original cluster - Example: PVC restored with ownerReference to old GlanceAPI UID - GlanceAPI NOT restored (operator-managed) - Operator creates NEW GlanceAPI with NEW UID - PVC is orphaned (UID mismatch) - Risk: Operator might delete/recreate PVC → DATA LOSS The Solution: - Use resourceModifiers with `conditions: {}` to match ALL resources - Strip ownerReferences during restore - Operators adopt resources during reconciliation - Operators set correct ownerReferences with new UIDs Implementation: - Applied to ALL restore orders (00, 10, 20, 30, 40, 60) for consistency - Simple pattern: `conditions: {}` matches all resource types - No need to enumerate specific groupResource values - Future-proof for any new resource types Updated: - Added "OwnerReference Handling" section explaining the problem/solution - Updated all example Restore CRs to use resourceModifiers - Updated Phase 3 manual restore examples (all orders) - Added note to Key Points section - Consistent pattern everywhere: `conditions: {}` for simplicity Benefits: - No orphaned resources - Operators can adopt and manage resources correctly - Prevents data loss (PVCs won't be recreated) - Clean ownership chain after restore - Simple, consistent approach Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 17758a6 commit b5f3421

1 file changed

Lines changed: 77 additions & 2 deletions

File tree

docs/dev/backup-restore-webhook-design.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,38 @@ This means:
491491
- Operator-created ConfigMaps → Not labeled → Not restored, recreated by operator ✅
492492
- All CRs with annotations → Labeled by webhook → Restored ✅
493493
494+
#### OwnerReference Handling
495+
496+
**The Problem:**
497+
498+
When OADP restores resources, each resource gets a NEW UID (UIDs are cluster-unique identifiers). However, backed-up ownerReferences contain OLD UIDs from the original cluster. This causes:
499+
500+
1. **Orphaned resources**: Restored resource has ownerReference with old UID that doesn't match the new owner's UID
501+
2. **Broken ownership chain**: Kubernetes doesn't recognize the ownership relationship
502+
3. **Potential data loss**: Operators might try to delete/recreate PVCs when they don't recognize them as owned resources
503+
504+
**Example:**
505+
```yaml
506+
# Backup: PVC owned by GlanceAPI
507+
metadata:
508+
name: glance-pvc
509+
ownerReferences:
510+
- uid: old-glance-uid-123 # Old UID from backup
511+
512+
# After restore:
513+
# - PVC has ownerReference: old-glance-uid-123
514+
# - GlanceAPI NOT restored (operator-managed)
515+
# - Operator creates NEW GlanceAPI with NEW UID: new-glance-uid-456
516+
# - PVC is orphaned (UID mismatch)
517+
# - Operator might delete/recreate PVC → DATA LOSS!
518+
```
519+
520+
**The Solution:**
521+
522+
Use OADP `resourceModifiers` to **strip ALL ownerReferences** during restore. Operators will adopt resources during reconciliation and set correct ownerReferences with new UIDs.
523+
524+
**Applied to ALL restore orders** for simplicity and safety - no need to think about which resources need it.
525+
494526
**Example Restore CRs:**
495527

496528
```yaml
@@ -507,6 +539,13 @@ spec:
507539
openstack.org/backup-restore: "true"
508540
openstack.org/backup-restore-order: "10"
509541
restorePVs: false # Don't restore PVCs in this order
542+
# CRITICAL: Remove ownerReferences to prevent orphaned resources
543+
# Operators will adopt resources and set correct ownerReferences during reconciliation
544+
resourceModifiers:
545+
- conditions: {} # Match all resources
546+
patches:
547+
- operation: remove
548+
path: "/metadata/ownerReferences"
510549
---
511550
# Restore Order 20: TLS Issuers
512551
apiVersion: velero.io/v1
@@ -521,13 +560,21 @@ spec:
521560
openstack.org/backup-restore: "true"
522561
openstack.org/backup-restore-order: "20"
523562
restorePVs: false
563+
# Remove ownerReferences from all resources
564+
resourceModifiers:
565+
- conditions: {} # Match all resources
566+
patches:
567+
- operation: remove
568+
path: "/metadata/ownerReferences"
524569
---
525570
# And so on for each restore order...
571+
# NOTE: ALL restore orders use resourceModifiers to strip ownerReferences
526572
```
527573

528574
**Key Points:**
529575
- **Backup**: All user resources in namespace (all Secrets, ConfigMaps, CRs) - complete snapshot
530576
- **Restore**: Only resources with `openstack.org/backup-restore: "true"` label - selective filtering
577+
- **OwnerReferences Removed**: All restore orders use `resourceModifiers` to strip ownerReferences (prevents orphaned resources, operators adopt during reconciliation)
531578
- **Webhooks**: Add restore labels to user-provided resources (no ownerReferences)
532579
- **Operators**: Recreate their own Secrets/ConfigMaps on reconciliation (not restored from backup)
533580

@@ -1105,6 +1152,12 @@ spec:
11051152
openstack.org/backup-restore: "true"
11061153
openstack.org/backup-restore-order: "00"
11071154
restorePVs: true # CSI snapshots
1155+
# Remove ownerReferences to prevent orphaned resources (operators will adopt during reconciliation)
1156+
resourceModifiers:
1157+
- conditions: {} # Match all resources
1158+
patches:
1159+
- operation: remove
1160+
path: "/metadata/ownerReferences"
11081161
EOF
11091162
11101163
# Wait for completion (CSI snapshot restore may take time)
@@ -1125,6 +1178,12 @@ spec:
11251178
openstack.org/backup-restore: "true"
11261179
openstack.org/backup-restore-order: "10"
11271180
restorePVs: false
1181+
# Remove ownerReferences to prevent orphaned resources
1182+
resourceModifiers:
1183+
- conditions: {} # Match all resources
1184+
patches:
1185+
- operation: remove
1186+
path: "/metadata/ownerReferences"
11281187
EOF
11291188
11301189
# Wait for completion
@@ -1165,9 +1224,13 @@ spec:
11651224
openstack.org/backup-restore: "true"
11661225
openstack.org/backup-restore-order: "30"
11671226
restorePVs: false
1168-
# CRITICAL: Add staged deployment annotation during restore
1169-
# Prevents operator from starting full deployment immediately
11701227
resourceModifiers:
1228+
# Remove ownerReferences from all resources
1229+
- conditions: {} # Match all resources
1230+
patches:
1231+
- operation: remove
1232+
path: "/metadata/ownerReferences"
1233+
# Add staged deployment annotation to OpenStackControlPlane
11711234
- conditions:
11721235
groupResource: openstackcontrolplanes.core.openstack.org
11731236
patches:
@@ -1198,6 +1261,12 @@ spec:
11981261
openstack.org/backup-restore: "true"
11991262
openstack.org/backup-restore-order: "40"
12001263
restorePVs: false
1264+
# Remove ownerReferences from all resources
1265+
resourceModifiers:
1266+
- conditions: {} # Match all resources
1267+
patches:
1268+
- operation: remove
1269+
path: "/metadata/ownerReferences"
12011270
EOF
12021271
12031272
oc wait --for=jsonpath='{.status.phase}'=Completed \
@@ -1245,6 +1314,12 @@ spec:
12451314
openstack.org/backup-restore: "true"
12461315
openstack.org/backup-restore-order: "60"
12471316
restorePVs: false
1317+
# Remove ownerReferences from all resources
1318+
resourceModifiers:
1319+
- conditions: {} # Match all resources
1320+
patches:
1321+
- operation: remove
1322+
path: "/metadata/ownerReferences"
12481323
EOF
12491324
12501325
oc wait --for=jsonpath='{.status.phase}'=Completed \

0 commit comments

Comments
 (0)