Skip to content

Commit e7d7077

Browse files
authored
interface: Add deletion behavior to ClusterResourcePlacement API (#140)
1 parent 0e90c29 commit e7d7077

11 files changed

+199
-12
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ type RolloutStrategy struct {
488488
// ApplyStrategy describes when and how to apply the selected resources to the target cluster.
489489
// +kubebuilder:validation:Optional
490490
ApplyStrategy *ApplyStrategy `json:"applyStrategy,omitempty"`
491+
492+
// DeleteStrategy configures the deletion behavior when the ClusterResourcePlacement is deleted.
493+
// +kubebuilder:validation:Optional
494+
DeleteStrategy *DeleteStrategy `json:"deleteStrategy,omitempty"`
491495
}
492496

493497
// ApplyStrategy describes when and how to apply the selected resource to the target cluster.
@@ -1319,6 +1323,38 @@ const (
13191323
PickFixedPlacementType PlacementType = "PickFixed"
13201324
)
13211325

1326+
// DeleteStrategy configures the deletion behavior when a placement is deleted.
1327+
type DeleteStrategy struct {
1328+
// PropagationPolicy controls whether to delete placed resources when placement is deleted.
1329+
//
1330+
// Available options:
1331+
//
1332+
// * Delete: all placed resources on member clusters will be deleted when
1333+
// the placement is deleted. This is the default behavior.
1334+
//
1335+
// * Abandon: all placed resources on member clusters will be left intact (abandoned)
1336+
// when the placement is deleted.
1337+
//
1338+
// +kubebuilder:validation:Enum=Abandon;Delete
1339+
// +kubebuilder:default=Delete
1340+
// +kubebuilder:validation:Optional
1341+
PropagationPolicy DeletePropagationPolicy `json:"propagationPolicy,omitempty"`
1342+
}
1343+
1344+
// DeletePropagationPolicy identifies the propagation policy when a placement is deleted.
1345+
// +enum
1346+
type DeletePropagationPolicy string
1347+
1348+
const (
1349+
// DeletePropagationPolicyAbandon instructs Fleet to leave (abandon) all placed resources on member
1350+
// clusters when the placement is deleted.
1351+
DeletePropagationPolicyAbandon DeletePropagationPolicy = "Abandon"
1352+
1353+
// DeletePropagationPolicyDelete instructs Fleet to delete all placed resources on member clusters
1354+
// when the placement is deleted. This is the default behavior.
1355+
DeletePropagationPolicyDelete DeletePropagationPolicy = "Delete"
1356+
)
1357+
13221358
// ClusterResourcePlacementList contains a list of ClusterResourcePlacement.
13231359
// +kubebuilder:resource:scope="Cluster"
13241360
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/placement.kubernetes-fleet.io_clusterresourcebindings.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ spec:
542542
managed by Fleet (i.e., specified in the hub cluster manifest). This is the default
543543
option.
544544
545-
Note that this option would revert any ad-hoc changes made on the member cluster side in
546-
the managed fields; if you would like to make temporary edits on the member cluster side
545+
Note that this option would revert any ad-hoc changes made on the member cluster side in the
546+
managed fields; if you would like to make temporary edits on the member cluster side
547547
in the managed fields, switch to IfNotDrifted option. Note that changes in unmanaged
548548
fields will be left alone; if you use the FullDiff compare option, such changes will
549549
be reported as drifts.

config/crd/bases/placement.kubernetes-fleet.io_clusterresourceplacements.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,28 @@ spec:
19051905
- Never
19061906
type: string
19071907
type: object
1908+
deleteStrategy:
1909+
description: DeleteStrategy configures the deletion behavior when
1910+
the ClusterResourcePlacement is deleted.
1911+
properties:
1912+
propagationPolicy:
1913+
default: Delete
1914+
description: |-
1915+
PropagationPolicy controls how the deletion is propagated to placed resources.
1916+
Defaults to "Delete".
1917+
1918+
Available options:
1919+
1920+
* Delete: all placed resources on member clusters will be deleted when the
1921+
ClusterResourcePlacement is deleted. This is the default behavior.
1922+
1923+
* Abandon: all placed resources on member clusters will be left intact (abandoned)
1924+
when the ClusterResourcePlacement is deleted.
1925+
enum:
1926+
- Abandon
1927+
- Delete
1928+
type: string
1929+
type: object
19081930
rollingUpdate:
19091931
description: Rolling update config params. Present only if RolloutStrategyType
19101932
= RollingUpdate.

config/crd/bases/placement.kubernetes-fleet.io_clusterresourcesnapshots.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ spec:
4040
Each snapshot MUST have the following labels:
4141
- `CRPTrackingLabel` which points to its owner CRP.
4242
- `ResourceIndexLabel` which is the index of the snapshot group.
43+
44+
The first snapshot of the index group MAY have the following labels:
4345
- `IsLatestSnapshotLabel` which indicates whether the snapshot is the latest one.
4446
4547
All the snapshots within the same index group must have the same ResourceIndexLabel.
@@ -50,6 +52,9 @@ spec:
5052
5153
Each snapshot (excluding the first snapshot) MUST have the following annotations:
5254
- `SubindexOfResourceSnapshotAnnotation` to store the subindex of resource snapshot in the group.
55+
56+
Snapshot may have the following annotations to indicate the time of next resourceSnapshot candidate detected by the controller:
57+
- `NextResourceSnapshotCandidateDetectionTimeAnnotation` to store the time of next resourceSnapshot candidate detected by the controller.
5358
properties:
5459
apiVersion:
5560
description: |-
@@ -186,6 +191,9 @@ spec:
186191
187192
Each snapshot (excluding the first snapshot) MUST have the following annotations:
188193
- `SubindexOfResourceSnapshotAnnotation` to store the subindex of resource snapshot in the group.
194+
195+
Snapshot may have the following annotations to indicate the time of next resourceSnapshot candidate detected by the controller:
196+
- `NextResourceSnapshotCandidateDetectionTimeAnnotation` to store the time of next resourceSnapshot candidate detected by the controller.
189197
properties:
190198
apiVersion:
191199
description: |-

config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ spec:
235235
managed by Fleet (i.e., specified in the hub cluster manifest). This is the default
236236
option.
237237
238-
Note that this option would revert any ad-hoc changes made on the member cluster side in
239-
the managed fields; if you would like to make temporary edits on the member cluster side
238+
Note that this option would revert any ad-hoc changes made on the member cluster side in the
239+
managed fields; if you would like to make temporary edits on the member cluster side
240240
in the managed fields, switch to IfNotDrifted option. Note that changes in unmanaged
241241
fields will be left alone; if you use the FullDiff compare option, such changes will
242242
be reported as drifts.
@@ -1315,8 +1315,8 @@ spec:
13151315
managed by Fleet (i.e., specified in the hub cluster manifest). This is the default
13161316
option.
13171317
1318-
Note that this option would revert any ad-hoc changes made on the member cluster side in
1319-
the managed fields; if you would like to make temporary edits on the member cluster side
1318+
Note that this option would revert any ad-hoc changes made on the member cluster side in the
1319+
managed fields; if you would like to make temporary edits on the member cluster side
13201320
in the managed fields, switch to IfNotDrifted option. Note that changes in unmanaged
13211321
fields will be left alone; if you use the FullDiff compare option, such changes will
13221322
be reported as drifts.

config/crd/bases/placement.kubernetes-fleet.io_resourcebindings.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ spec:
190190
managed by Fleet (i.e., specified in the hub cluster manifest). This is the default
191191
option.
192192
193-
Note that this option would revert any ad-hoc changes made on the member cluster side in
194-
the managed fields; if you would like to make temporary edits on the member cluster side
193+
Note that this option would revert any ad-hoc changes made on the member cluster side in the
194+
managed fields; if you would like to make temporary edits on the member cluster side
195195
in the managed fields, switch to IfNotDrifted option. Note that changes in unmanaged
196196
fields will be left alone; if you use the FullDiff compare option, such changes will
197197
be reported as drifts.

config/crd/bases/placement.kubernetes-fleet.io_resourceplacements.yaml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ spec:
742742
managed by Fleet (i.e., specified in the hub cluster manifest). This is the default
743743
option.
744744
745-
Note that this option would revert any ad-hoc changes made on the member cluster side in
746-
the managed fields; if you would like to make temporary edits on the member cluster side
745+
Note that this option would revert any ad-hoc changes made on the member cluster side in the
746+
managed fields; if you would like to make temporary edits on the member cluster side
747747
in the managed fields, switch to IfNotDrifted option. Note that changes in unmanaged
748748
fields will be left alone; if you use the FullDiff compare option, such changes will
749749
be reported as drifts.
@@ -840,6 +840,28 @@ spec:
840840
- Never
841841
type: string
842842
type: object
843+
deleteStrategy:
844+
description: DeleteStrategy configures the deletion behavior when
845+
the ClusterResourcePlacement is deleted.
846+
properties:
847+
propagationPolicy:
848+
default: Delete
849+
description: |-
850+
PropagationPolicy controls how the deletion is propagated to placed resources.
851+
Defaults to "Delete".
852+
853+
Available options:
854+
855+
* Delete: all placed resources on member clusters will be deleted when the
856+
ClusterResourcePlacement is deleted. This is the default behavior.
857+
858+
* Abandon: all placed resources on member clusters will be left intact (abandoned)
859+
when the ClusterResourcePlacement is deleted.
860+
enum:
861+
- Abandon
862+
- Delete
863+
type: string
864+
type: object
843865
rollingUpdate:
844866
description: Rolling update config params. Present only if RolloutStrategyType
845867
= RollingUpdate.

config/crd/bases/placement.kubernetes-fleet.io_resourcesnapshots.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ spec:
4040
Each snapshot MUST have the following labels:
4141
- `CRPTrackingLabel` which points to its owner resource placement.
4242
- `ResourceIndexLabel` which is the index of the snapshot group.
43+
44+
The first snapshot of the index group MAY have the following labels:
4345
- `IsLatestSnapshotLabel` which indicates whether the snapshot is the latest one.
4446
4547
All the snapshots within the same index group must have the same ResourceIndexLabel.

0 commit comments

Comments
 (0)