Created
December 6, 2021 16:21
-
-
Save gallettilance/703c1521744a1df2d5ed4af4e1ecb0e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myKindFinalizer = "grp.example.com/finalizer" | |
// DeletionReconciler controls the reconciliation of deleted resources | |
func (r *MykindReconciler) deletionReconciler(ctx context.Context, cr *grpv1alpha1.Mykind) (ctrl.Result, error) { | |
// Finalizer logic here | |
// More on finalizers: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#finalizers | |
if controllerutil.ContainsFinalizer(cr, myKindFinalizer) { | |
// our finalizer is present, so lets handle any external dependency | |
if err := r.doCleanup(cr); err != nil { | |
// if fail to delete the external dependency here, return with error | |
// so that it can be retried | |
return r.manageDeleteFailure(ctx, cr, err) | |
} | |
// remove our finalizer from the list and update it. | |
controllerutil.RemoveFinalizer(cr, myKindFinalizer) | |
if err := r.Update(ctx, cr); err != nil { | |
return r.manageDeleteFailure(ctx, cr, err) | |
} | |
} | |
// Stop reconciliation as the item is being deleted | |
return r.manageDeleteSuccess(ctx, cr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment