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

🐛 Clean up and namespace verification while removing owner ref and controller ref #2958

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

HiranmoyChowdhury
Copy link

@HiranmoyChowdhury HiranmoyChowdhury commented Sep 23, 2024

Signed-off-by: Hiranmoy Das Chowdhury [email protected]

As we know for a resource there only one name can be allocated for every individual namespace. So, when we are removing ownerRef or controllerRef from an controlled object by passing the owner object, we are only checking the name+group+kind but not the namespace. To verify this I added namespace verification and also did some cleanup.

Signed-off-by: Hiranmoy Das Chowdhury <[email protected]>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 23, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: HiranmoyChowdhury
Once this PR has been reviewed and has the lgtm label, please assign joelanford for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
Contributor

Hi @HiranmoyChowdhury. 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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 23, 2024
@HiranmoyChowdhury
Copy link
Author

As there can be only one Controller Reference, then we should have something which only removes the controllerReference. Here the function named "RemoveControllerReference" removes controller reference if that matched with the given object. This way should only applicable for OwnerReference I guess. Should I change this too or make a new function?

@HiranmoyChowdhury HiranmoyChowdhury changed the title clean up and fixed referSameObject function Clean up and Fixed referSameObject function Sep 23, 2024
Comment on lines 240 to 241
func referSameObject(a, b metav1.OwnerReference) bool {
aGV, err := schema.ParseGroupVersion(a.APIVersion)
if err != nil {
return false
}

bGV, err := schema.ParseGroupVersion(b.APIVersion)
if err != nil {
return false
}
return aGV.Group == bGV.Group && a.Kind == b.Kind && a.Name == b.Name
return a.UID == b.UID
Copy link
Member

Choose a reason for hiding this comment

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

/hold

No, this isn't correct as UIDs can change across backups and clusters. References should be compared like above

Copy link
Author

Choose a reason for hiding this comment

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

Got it. I am gonna change this and I guess rest are okay

Copy link
Author

Choose a reason for hiding this comment

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

Now this will ensure owner by validating namespace while removing owner ref or controller ref

@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 Sep 24, 2024
return idx != -1, nil
}

// RemoveControllerReference removes an owner reference where the controller
// equals true
func RemoveControllerReference(owner, object metav1.Object, scheme *runtime.Scheme) error {
if ok := HasControllerReference(object); !ok {
return fmt.Errorf("%T does not have a owner reference with controller equals true", object)
if !metav1.IsControlledBy(object, owner) {
Copy link
Member

Choose a reason for hiding this comment

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

This error is now misleading because if the object doesn’t have a controller reference the returned error will only indicate that the owner being passed is not the controller reference for the object.

The error before allowed you to recognize if the object you are passing in had one at all before trying to remove it with the owner passed in.

Copy link
Member

Choose a reason for hiding this comment

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

#2595 (comment) Discussion for why the logic exists was from several issues with how to get around overwriting and errors that exist with controller reference/owner reference.

Copy link
Author

Choose a reason for hiding this comment

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

okay. gonna change it soon

Copy link
Author

@HiranmoyChowdhury HiranmoyChowdhury Sep 24, 2024

Choose a reason for hiding this comment

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

@troy0820 WDYT about this: #2958 (comment)

…er reference and fix error messages for not having controller reference

Signed-off-by: Hiranmoy Das Chowdhury <[email protected]>
@HiranmoyChowdhury HiranmoyChowdhury changed the title Clean up and Fixed referSameObject function Clean up and namespace verification while removing owner ref and controller ref Sep 24, 2024
@HiranmoyChowdhury HiranmoyChowdhury changed the title Clean up and namespace verification while removing owner ref and controller ref 🐛 Clean up and namespace verification while removing owner ref and controller ref Sep 24, 2024
Signed-off-by: Hiranmoy Das Chowdhury <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants