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

How to delete a custom object and wait until it is cleaned up with propagation_policy #2161

Open
TrafalgarZZZ opened this issue Dec 18, 2023 · 2 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@TrafalgarZZZ
Copy link

What is the feature and why do you need it:
I'm trying to use Kubernetes python sdk to delete a CR with custom_api.delete_namespaced_custom_object. My CR has a finalizer and a controller will clean some dependant resources when a deletionTimeStamp is added on the CR. When the resources are cleaned up, the finalizer will be removed and the CR will then be cleaned up. My question is that how can I make the custom_api.delete_namespaced_custom_object fucntion return after my CR is cleaned up.

I've tried adding propagation_policy='Foreground' and 'Background' as a parameter to the function but it does not work: It deletes the CR, returns immediately but doesn't wait for it to be cleaned up.

kwargs = {
  "propagation_policy": "Foreground",  # or "Background"
  "grace_period_seconds: 120
}

self.custom_api.delete_namespaced_custom_object(
                "example.com",
                "v1alpha1",
                "default",
                "mycrds",
               "demo-cr",
               **kwargs
            )

Is it possible to implement this feature using propagation_policy or any other similar techniques?

Describe the solution you'd like to see:

self.custom_api.delete_namespaced_custom_object(..., propagation_policy="Foreground")

Such code may block until the CR is really deleted.

@TrafalgarZZZ TrafalgarZZZ added the kind/feature Categorizes issue or PR as related to a new feature. label Dec 18, 2023
@roycaihw
Copy link
Member

Your usage of Foreground policy is correct.

However, delete_namespaced_custom_object does not block on object deletion. You need to write your own code to wait for the object to be non-existing. kubectl achieves it by sending multiple API calls to the server. You can try running kubectl with -v=9 to see what APIs kubectl uses to wait for the deletion to finish.

Ref: https://kubernetes.io/docs/concepts/architecture/garbage-collection/#cascading-deletion

@k8s-triage-robot
Copy link

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

This bot triages un-triaged issues 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 as fresh with /remove-lifecycle stale
  • Close this issue 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 May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. 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