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

AddOwnerRef should update #159

Merged
merged 1 commit into from
Apr 23, 2020
Merged

AddOwnerRef should update #159

merged 1 commit into from
Apr 23, 2020

Conversation

muvaf
Copy link
Member

@muvaf muvaf commented Apr 22, 2020

Signed-off-by: Muvaffak Onus onus.muvaffak@gmail.com

Description of your changes

AddOwnerReference should always set the owner ref array to be able to modify the existing reference. Otherwise it never updates the existing owner ref.

Checklist

I have:

  • Run make reviewable to ensure this PR is ready for review.
  • Ensured this PR contains a neat, self documenting set of commits.
  • Updated any relevant documentation, examples, or release notes.
  • Updated the RBAC permissions in clusterrole.yaml to include any new types.

… modify the existing reference

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
@muvaf muvaf requested a review from negz April 22, 2020 20:32
Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

LGTM!

@negz
Copy link
Member

negz commented Apr 23, 2020

Are you sure this is necessary? Typically I'd expect this to work per https://play.golang.org/p/KXo6vizZol2.

@muvaf
Copy link
Member Author

muvaf commented Apr 23, 2020

Typically I'd expect this to work per https://play.golang.org/p/KXo6vizZol2.

I'm not able to access this as Go playground seems to be down.

Are you sure this is necessary?

Since GetOwnerReferences() []OwnerReference returns a copy of the owner references refs[i] = ref does pretty much nothing. I've run into this in an edge case where the object was owner but not controller and the owner ref didn't get updated because set never called. It'd be more correct if we actually updated the owner ref if it already exists or skip the case where it already exists altogether.

@negz
Copy link
Member

negz commented Apr 23, 2020

Since GetOwnerReferences() []OwnerReference returns a copy of the owner references refs[i] = ref does pretty much nothing.

I suspect this might only be the case for *unstructured.Unstructured. Types that embed metav1.ObjectMeta just return the underlying struct, which is probably why we haven't noticed this until now. Either way, it doesn't seem safe to assume that the underlying struct is being returned and can be modified in place.

@negz negz merged commit 1cd8a32 into crossplane:master Apr 23, 2020
@muvaf muvaf deleted the setowner branch April 23, 2020 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants