|
| 1 | +# CRP Delete Policy Implementation |
| 2 | + |
| 3 | +## Problem Analysis |
| 4 | + |
| 5 | +The issue requests adding API options to allow customers to choose whether to delete placed resources when a CRP (ClusterResourcePlacement) is deleted. |
| 6 | + |
| 7 | +### Current Deletion Behavior |
| 8 | +1. When a CRP is deleted, it has two finalizers: |
| 9 | + - `ClusterResourcePlacementCleanupFinalizer` - handled by CRP controller to delete snapshots |
| 10 | + - `SchedulerCleanupFinalizer` - handled by scheduler to delete bindings |
| 11 | + |
| 12 | +2. The deletion flow: |
| 13 | + - CRP controller removes snapshots (ClusterSchedulingPolicySnapshot, ClusterResourceSnapshot) |
| 14 | + - Scheduler removes bindings (ClusterResourceBinding) which triggers cleanup of placed resources |
| 15 | + - Currently there's no option for users to control whether placed resources are deleted |
| 16 | + |
| 17 | +### References |
| 18 | +- Kubernetes DeleteOptions has `PropagationPolicy` with values: `Orphan`, `Background`, `Foreground` |
| 19 | +- AKS API has `DeletePolicy` pattern (couldn't fetch exact details but following similar pattern) |
| 20 | + |
| 21 | +## Implementation Plan |
| 22 | + |
| 23 | +### Phase 1: API Design |
| 24 | +- [x] Add `DeleteStrategy` struct to `RolloutStrategy` in beta API |
| 25 | +- [x] Define `PropagationPolicy` field with enum values: `Delete` (default), `Abandon` |
| 26 | +- [x] Update API documentation and validation |
| 27 | +- [x] Move DeleteStrategy inside RolloutStrategy after ApplyStrategy for consistency |
| 28 | + |
| 29 | +### Phase 2: Implementation Details |
| 30 | +TODO: @Arvindthiru to fill out the details for controller logic implementation. |
| 31 | + |
| 32 | +### Phase 3: Testing |
| 33 | +- [ ] Add unit tests for new deletion policy options |
| 34 | +- [ ] Add integration tests to verify behavior |
| 35 | +- [ ] Test both `Delete` and `Abandon` scenarios |
| 36 | + |
| 37 | +### Phase 4: Documentation & Examples |
| 38 | +- [ ] Update CRD documentation |
| 39 | +- [ ] Add example configurations |
| 40 | +- [ ] Update any user-facing documentation |
| 41 | + |
| 42 | +## Success Criteria |
| 43 | +- [x] CRP API has `deleteStrategy` field with `Delete`/`Abandon` options inside RolloutStrategy |
| 44 | +- [x] Default behavior (`Delete`) preserves current functionality |
| 45 | +- [ ] `Abandon` policy leaves placed resources intact when CRP is deleted |
| 46 | +- [ ] All tests pass including new deletion policy tests |
| 47 | +- [x] Changes are minimal and backwards compatible |
| 48 | + |
| 49 | +## Current API Structure |
| 50 | + |
| 51 | +The DeleteStrategy is now part of RolloutStrategy: |
| 52 | + |
| 53 | +```go |
| 54 | +type RolloutStrategy struct { |
| 55 | + // ... other fields ... |
| 56 | + ApplyStrategy *ApplyStrategy `json:"applyStrategy,omitempty"` |
| 57 | + DeleteStrategy *DeleteStrategy `json:"deleteStrategy,omitempty"` |
| 58 | +} |
| 59 | + |
| 60 | +type DeleteStrategy struct { |
| 61 | + PropagationPolicy DeletePropagationPolicy `json:"propagationPolicy,omitempty"` |
| 62 | +} |
| 63 | + |
| 64 | +type DeletePropagationPolicy string |
| 65 | + |
| 66 | +const ( |
| 67 | + DeletePropagationPolicyDelete DeletePropagationPolicy = "Delete" // default |
| 68 | + DeletePropagationPolicyAbandon DeletePropagationPolicy = "Abandon" |
| 69 | +) |
| 70 | +``` |
| 71 | + |
| 72 | +## Behavior Summary |
| 73 | + |
| 74 | +- **Default (`Delete`)**: When CRP is deleted, all placed resources are removed from member clusters (current behavior) |
| 75 | +- **Abandon**: When CRP is deleted, placed resources remain on member clusters but are no longer managed by Fleet |
| 76 | + |
| 77 | +This provides customers with the flexibility to choose between complete cleanup or leaving resources in place when deleting a CRP. |
0 commit comments