Skip to content

Commit a4d6405

Browse files
Merge pull request #594 from sector2000/make-cascade-deletion-optional
Make cascade deletion optional
2 parents 9942678 + 856248f commit a4d6405

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Search OperatorHub for "pattern" and accept all the defaults
1515
## Create the Multi-Cloud GitOps pattern
1616

1717
```
18-
kubectl create -f config/samples/gitops_v1alpha1_pattern.yaml
18+
oc create -f config/samples/gitops_v1alpha1_pattern.yaml
1919
```
2020

2121
### Check the status
2222

2323
```
24-
kubectl get -f config/samples/gitops_v1alpha1_pattern.yaml -o yaml
24+
oc get -f config/samples/gitops_v1alpha1_pattern.yaml -o yaml
2525
oc get applications -A -w
2626
```
2727

@@ -36,21 +36,27 @@ secret and then add the secrets via the UI (this approach is a bit more work)
3636
### Delete the pattern
3737

3838
```
39-
kubectl delete -f config/samples/gitops_v1alpha1_pattern.yaml
39+
oc delete -f config/samples/gitops_v1alpha1_pattern.yaml
4040
```
4141

42-
This will only remove the top-level application.
43-
The subscription and anything created by Argo will not be removed and canmust be removed manually.
44-
Removing the top-level application ensures that Argo won't try to put back anything you delete.
42+
This action removes the `Pattern` instance only.
4543

46-
## Watch the logs
47-
48-
When installing via UI the namespace will be `patterns-operator` (recommended)
44+
If you annotate the Pattern instance with `patterns.gitops.hybrid-cloud-patterns.io/prune: "true"`:
4945

5046
```
51-
oc logs -n patterns-operator `oc get -n patterns-operator pods -o name --field-selector status.phase=Running | grep patterns` -c manager -f
47+
oc annotate -f config/samples/gitops_v1alpha1_pattern.yaml patterns.gitops.hybrid-cloud-patterns.io/prune='true'
5248
```
5349

50+
Once the `Pattern` instance is deleted, the following resources will also be removed:
51+
52+
- The top-level application of the hub cluster.
53+
- The child applications of the hub cluster.
54+
- The top-level application of the spoke clusters.
55+
- The child applications of the spoke clusters.
56+
- The `ManagedCluster` instances (excluding the `local-cluster`).
57+
58+
**NOTE:** The GitOps Operator `Subscription` and the main `ArgoCD` instance will not be removed and must be removed manually.
59+
5460
## Development
5561

5662
### Test your changes locally against a remote cluster

internal/controller/pattern_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import (
6868
)
6969

7070
const ReconcileLoopRequeueTime = 180 * time.Second
71+
const PruneAnnotation = "patterns.gitops.hybrid-cloud-patterns.io/prune"
7172

7273
// PatternReconciler reconciles a Pattern object
7374
type PatternReconciler struct {
@@ -748,11 +749,11 @@ func (r *PatternReconciler) deleteHubApps(targetApp, app *argoapi.Application, n
748749
}
749750

750751
func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
751-
// Add finalizer when object is created
752752
log.Printf("Finalizing pattern object")
753753

754-
// The object is being deleted
755-
if controllerutil.ContainsFinalizer(instance, api.PatternFinalizer) || controllerutil.ContainsFinalizer(instance, metav1.FinalizerOrphanDependents) {
754+
// The object is being deleted and, if prune is enabled, we want to delete all the dependent objects in cascade
755+
if strings.EqualFold(instance.Annotations[PruneAnnotation], "true") &&
756+
(controllerutil.ContainsFinalizer(instance, api.PatternFinalizer) || controllerutil.ContainsFinalizer(instance, metav1.FinalizerOrphanDependents)) {
756757
// Prepare the app for cascaded deletion
757758
qualifiedInstance, err := r.applyDefaults(instance)
758759
if err != nil {

0 commit comments

Comments
 (0)