Skip to content

Commit 856248f

Browse files
committed
Make cascade deletion optional
1 parent d413b03 commit 856248f

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
@@ -67,6 +67,7 @@ import (
6767
)
6868

6969
const ReconcileLoopRequeueTime = 180 * time.Second
70+
const PruneAnnotation = "patterns.gitops.hybrid-cloud-patterns.io/prune"
7071

7172
// PatternReconciler reconciles a Pattern object
7273
type PatternReconciler struct {
@@ -740,11 +741,11 @@ func (r *PatternReconciler) deleteHubApps(targetApp, app *argoapi.Application, n
740741
}
741742

742743
func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
743-
// Add finalizer when object is created
744744
log.Printf("Finalizing pattern object")
745745

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

0 commit comments

Comments
 (0)