diff --git a/README.md b/README.md index 1c7d1de..d3045c6 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,23 @@ spec: - 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! diff --git a/controllers/clusterrelocation_controller.go b/controllers/clusterrelocation_controller.go index 5fe2c84..848c700 100644 --- a/controllers/clusterrelocation_controller.go +++ b/controllers/clusterrelocation_controller.go @@ -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)