Skip to content

Commit 49ab3eb

Browse files
zhujian7claude
andcommitted
Add documentation for addon deletion-orphan annotation
This commit adds comprehensive documentation for the addon.open-cluster-management.io/deletion-orphan annotation that allows addon developers to preserve specific resources when an addon is deleted. Changes include: - New section "Orphaning manifests on addon deletion" explaining the deletion-orphan annotation - Usage examples and use cases for orphaning resources - Complete example with PersistentVolumeClaim preservation - Integration with addon template documentation showing the annotation can be used in AddOnTemplate manifests - Example in the AddOnTemplate YAML demonstrating the annotation This documentation is based on the implementation in addon-framework/pkg/addonmanager/controllers/agentdeploy/utils.go (getDeletionOrphaningRule function). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]>
1 parent ad8d2cf commit 49ab3eb

File tree

1 file changed

+98
-1
lines changed
  • content/en/docs/developer-guides

1 file changed

+98
-1
lines changed

content/en/docs/developer-guides/addon.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,101 @@ After the `Jobs` are `Completed` or `Pods` are in the `Succeeded` phase, all the
837837

838838
You can find the example from [here](https://github.com/open-cluster-management-io/addon-framework/tree/main/examples/helloworld_helm).
839839

840+
## Orphaning manifests on addon deletion
841+
842+
By default, when a `ManagedClusterAddOn` is deleted, all the resources deployed by the addon will be automatically removed from the managed cluster. However, in some cases, you may want to preserve certain resources even after the addon is deleted. The addon-framework provides the `addon.open-cluster-management.io/deletion-orphan` annotation to support this use case.
843+
844+
When you add this annotation to any resource in your addon manifests, that resource will be "orphaned" (left behind) when the addon is deleted, instead of being automatically cleaned up.
845+
846+
### How to use the deletion-orphan annotation
847+
848+
Add the `addon.open-cluster-management.io/deletion-orphan` annotation to any resources in your addon manifests that you want to preserve after addon deletion:
849+
850+
```yaml
851+
kind: ConfigMap
852+
apiVersion: v1
853+
metadata:
854+
name: important-data
855+
namespace: open-cluster-management-agent-addon
856+
annotations:
857+
addon.open-cluster-management.io/deletion-orphan: ""
858+
data:
859+
key: value
860+
```
861+
862+
When the `ManagedClusterAddOn` is deleted:
863+
864+
1. Resources **without** the `deletion-orphan` annotation will be removed from the managed cluster
865+
2. Resources **with** the `deletion-orphan` annotation will remain on the managed cluster
866+
867+
### Use cases
868+
869+
Common scenarios where orphaning manifests is useful:
870+
871+
* **Preserving data:** Keep ConfigMaps or Secrets containing important configuration or state data
872+
* **Avoiding disruption:** Leave certain resources running to prevent service interruption during addon reinstallation
873+
* **Manual cleanup:** Retain resources that need manual review or cleanup by administrators
874+
* **Shared resources:** Keep resources that might be used by other components or addons
875+
876+
### Important notes
877+
878+
* The annotation value can be empty (`""`) or any string - only the presence of the annotation key matters
879+
* Orphaned resources will not be managed by OCM after the addon is deleted. You'll need to clean them up manually if needed
880+
* This annotation works for any Kubernetes resource type in your addon manifests
881+
* You can combine this with the [pre-delete hook](#pre-delete-hook) to run cleanup jobs while preserving certain resources
882+
883+
### Example: Orphaning a PersistentVolumeClaim
884+
885+
Here's an example of an addon that deploys a stateful application and preserves the PersistentVolumeClaim when the addon is deleted:
886+
887+
```yaml
888+
kind: Deployment
889+
apiVersion: apps/v1
890+
metadata:
891+
name: stateful-app
892+
namespace: open-cluster-management-agent-addon
893+
spec:
894+
replicas: 1
895+
selector:
896+
matchLabels:
897+
app: stateful-app
898+
template:
899+
metadata:
900+
labels:
901+
app: stateful-app
902+
spec:
903+
containers:
904+
- name: app
905+
image: my-stateful-app:latest
906+
volumeMounts:
907+
- name: data
908+
mountPath: /data
909+
volumes:
910+
- name: data
911+
persistentVolumeClaim:
912+
claimName: app-data
913+
---
914+
kind: PersistentVolumeClaim
915+
apiVersion: v1
916+
metadata:
917+
name: app-data
918+
namespace: open-cluster-management-agent-addon
919+
annotations:
920+
addon.open-cluster-management.io/deletion-orphan: ""
921+
spec:
922+
accessModes:
923+
- ReadWriteOnce
924+
resources:
925+
requests:
926+
storage: 10Gi
927+
```
928+
929+
In this example, when the addon is deleted:
930+
931+
* The Deployment will be removed
932+
* The PersistentVolumeClaim will be preserved with its data intact
933+
* You can reinstall the addon later and it will reconnect to the existing PVC
934+
840935
## What happened under the scene
841936

842937
<div style="text-align: center; padding: 20px;">
@@ -937,7 +1032,7 @@ volumes, health probe for daemonsets) from OCM v0.14.0.
9371032

9381033
1. Create an `AddOnTemplate` object to define the addon:
9391034
The `AddOnTemplate` API provides two parts of information to build an addon:
940-
* `manifests`: what resources will be deployed to the managed cluster
1035+
* `manifests`: what resources will be deployed to the managed cluster. You can add the `addon.open-cluster-management.io/deletion-orphan` annotation to any resource to preserve it when the addon is deleted (see [Orphaning manifests on addon deletion](#orphaning-manifests-on-addon-deletion)).
9411036
* `registration`: how to register the addon to the hub cluster
9421037

9431038
For example, the following yaml file defines the `hello-template` addon, which will:
@@ -994,6 +1089,8 @@ volumes, health probe for daemonsets) from OCM v0.14.0.
9941089
metadata:
9951090
name: hello-template-agent-sa
9961091
namespace: open-cluster-management-agent-addon
1092+
annotations:
1093+
addon.open-cluster-management.io/deletion-orphan: "" # Optional: preserve this resource when addon is deleted
9971094
- kind: ClusterRoleBinding
9981095
apiVersion: rbac.authorization.k8s.io/v1
9991096
metadata:

0 commit comments

Comments
 (0)