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

🌱 Add function RemoveControllerReference and HasControllerReference #2509

Merged

Conversation

troy0820
Copy link
Member

  • Add function RemoveControllerReference to controllerutil
  • Add function HasControllerReference to controllerutil
  • Add tests for functions

When creating #2462 it was discussed that to achieve the ask of the issue #2381 two functions can help remove ControllerReferences to get around the errors of it not being able to be overwritten.

These two functions (and not to be confused with the original PR that allows removal of any owner reference), allows the caller to see if the owner reference they want to remove in fact is a "ControllerReference" (controller = true)

This functionality is present with finalizers and will be helpful when trying to mitigate issues with trying to overwrite the owner reference on an object.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 23, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 23, 2023
@troy0820 troy0820 force-pushed the troy0820/hascontrollerreference branch 2 times, most recently from 6c99348 to b4f0d66 Compare September 23, 2023 17:31
…controllerutil

Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
@troy0820 troy0820 force-pushed the troy0820/hascontrollerreference branch from b4f0d66 to da41833 Compare September 23, 2023 17:49
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 7, 2023
@k8s-ci-robot k8s-ci-robot merged commit 65ba74b into kubernetes-sigs:main Oct 7, 2023
9 checks passed

// RemoveControllerReference removes an owner reference where the controller
// equals true
func RemoveControllerReference(owner, object metav1.Object, scheme *runtime.Scheme) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@troy0820 Sorry for the late review :).

I'm not sure if this func works as intended. It first checks if there is a controller ownerRef on the object and then it removes the passed in owner. It doesn't check that the passed in owner is actually the controller (which I think is the goal of this func)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now looking at it, I’m not sure how I missed that. I’ll update the func to look if the owner is the controlled and remove that reference, otherwise it misses the goal as you said.

I’ll create an issue and assign it to me.

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. 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.

None yet

4 participants