Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples of the Finalizer Helper Library #1631

Closed
austince opened this issue Aug 13, 2021 · 2 comments
Closed

Examples of the Finalizer Helper Library #1631

austince opened this issue Aug 13, 2021 · 2 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@austince
Copy link

austince commented Aug 13, 2021

Are there any examples that use the new Finalizer helper library? I'm giving it a try but don't quite understand where the business logic of the finalizer should live. It feels like the Reconciler knows what should be deleted, not main.

Should I define the finalizer logic inside the x_controller.go file, and just register that in the main? Should the reconciler itself actually implement the Finalizer interface?

And then, does it make sense to requeue if either the obj or its status was updated?

requeue, err := r.Finalizers.Finalize(ctx, &job)
if requeue.Updated || requeue.StatusUpdated || err != nil {
  if requeue.Updated {
	r.Client.Update(ctx, &job)
  }

  if requeue.StatusUpdated {
	r.Client.Status().Update(ctx, &job)
  }
  return ctrl.Result{Requeue: requeue.Updated || requeue.StatusUpdated}, err
}

Thanks for the help!

Originally posted by @austince in #1453 (comment)

@varshaprasad96
Copy link
Member

Finalizers could be used to clean up any external resources across namespaces when the parent object is deleted. This example maybe helpful to have an overview on where finalizers could be used inside a controller.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

4 participants