Skip to content

Commit

Permalink
skip finalizer if orphaned deletion is requested (#68)
Browse files Browse the repository at this point in the history
* skip finalizer if orphaned deletion is requested

* fix typo
  • Loading branch information
loganmc10 authored Jul 7, 2023
1 parent 4615867 commit 169e837
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ spec:
- <new_ssh_key>
EOF
```
### Deleting the CR
When you delete the ClusterRelocation CR, everything will be reverted back to its original state.

If you would like to delete the CR, but keep the relocation configuration, you may add the `skip-finalizer: "true"` annotation:
```
apiVersion: rhsyseng.github.io/v1beta1
kind: ClusterRelocation
metadata:
name: cluster
annotations:
skip-finalizer: "true"
```
and then delete the CR like this:
```
oc delete clusterrelocation cluster --cascade=orphan
```
This will allow you to delete the CR (and the operator if desired), while keeping the new configuration.

## Contributing
This is a community project, feel free to open a PR and help out!
Expand Down
15 changes: 14 additions & 1 deletion controllers/clusterrelocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,26 @@ func (r *ClusterRelocationReconciler) Reconcile(ctx context.Context, req ctrl.Re
return ctrl.Result{}, nil
}

skipFinalizer := false
val, ok := relocation.Annotations["skip-finalizer"]
if ok {
if val == "true" {
skipFinalizer = true
}
}
// Add finalizer for this CR
if !controllerutil.ContainsFinalizer(relocation, relocationFinalizer) {
if !skipFinalizer && !controllerutil.ContainsFinalizer(relocation, relocationFinalizer) {
controllerutil.AddFinalizer(relocation, relocationFinalizer)
if err := r.Update(ctx, relocation); err != nil {
return ctrl.Result{}, err
}
logger.Info("Added finalizer to CR")
} else if skipFinalizer && controllerutil.ContainsFinalizer(relocation, relocationFinalizer) {
controllerutil.RemoveFinalizer(relocation, relocationFinalizer)
if err := r.Update(ctx, relocation); err != nil {
return ctrl.Result{}, err
}
logger.Info("Removed finalizer from CR")
}

defer r.updateStatus(ctx, relocation, logger)
Expand Down

0 comments on commit 169e837

Please sign in to comment.