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

✨ controllerutil: configure BlockOwnerDeletion when setting OwnerReference #2847

Merged

Conversation

muwaqar
Copy link
Contributor

@muwaqar muwaqar commented Jun 5, 2024

Currently, SetOwnerReference() and SetControllerReference() in controllerutil do not allow configuring BlockOwnerDeletion field of the underlying OwnerReference. This is limiting for scenarios where one would like to use these helper methods but configure BlockOwnerDeletion field in a different way than the current defaults.

Fixes #2846

@k8s-ci-robot
Copy link
Contributor

Welcome @muwaqar!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 5, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @muwaqar. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

linux-foundation-easycla bot commented Jun 5, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 5, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 5, 2024
@troy0820
Copy link
Member

troy0820 commented Jun 5, 2024

/hold

In your issue you state

controllerutil SetControllerReference() implementation necessarily sets BlockOwnerDeletion = ptr.To(true). This means that the user needs to explicitly delete the referent resource before the owner can be cleaned up (see foreground deletion details).
users should be able to configure BlockOwnerDeletion while using these utility methods conveniently

but doesn't that go against what we want to use SetControllerReference for?

Allowing the BlockOwnerDeletion to be configurable changes the intention of why that is necessary and may conflate the workflow with the owner/controller references.

The requisite helper functions alleviate the need to change the configuration of SetControllerReference by using RemoveControllerReferfence

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 5, 2024
@muwaqar
Copy link
Contributor Author

muwaqar commented Jun 5, 2024

but doesn't that go against what we want to use SetControllerReference for?

@troy0820: based on my understanding of the original ControllerRef proposal, the controller reference is used to identify the owning controller only so that multiple controllers with sharing labels do not clash over the resource, but does not dictate any behavior for garbage collection of owned resources, and says:

When a controller is deleted, the objects it owns will either be orphaned or deleted according to the normal Garbage Collection behavior, based on OwnerReferences.

i interpret this to be users should be able to configure the cascade deletion behavior.

@alvaroaleman
Copy link
Member

but doesn't that go against what we want to use SetControllerReference for?

Allowing the BlockOwnerDeletion to be configurable changes the intention of why that is necessary and may conflate the workflow with the owner/controller references.

The handler we have in Owns requires the ownerRef to have controller: true. Ending up with foreground deletion just because you use SetControllerRef is surprising IMHO, those two settings are orthogonal, if you do or do not want foreground deletion can not be derived from controller: true

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 5, 2024
@k8s-ci-robot
Copy link
Contributor

@muwaqar: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-apidiff 50abe5b link false /test pull-controller-runtime-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@sbueringer
Copy link
Member

Agree with what @muwaqar & @alvaroaleman wrote

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, muwaqar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 5, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b80abb6bc126e56415e0e2677b63ecdfdf422027

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 5, 2024
@alvaroaleman
Copy link
Member

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 5, 2024
@k8s-ci-robot k8s-ci-robot merged commit f9d51ba into kubernetes-sigs:main Jun 5, 2024
8 of 9 checks passed
@troy0820
Copy link
Member

troy0820 commented Jun 5, 2024

Thanks for the explanation @alvaroaleman and thanks for your contribution @muwaqar 🎉

@alvaroaleman
Copy link
Member

/cherrypick release-0.18

@k8s-infra-cherrypick-robot

@alvaroaleman: new pull request created: #2848

In response to this:

/cherrypick release-0.18

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

controllerutil: SetControllerReference does not allow disabling BlockOwnerDeletion
6 participants