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

🐛 Fix implicit aliasing issue in nested maps #810

Conversation

shyamradhakrishnan
Copy link
Contributor

Fix #809

The PR fixes the implicit memory aliasing issue in autogenerated DeepCopy method when the field is a nested map.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 8, 2023
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 8, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 8, 2023
@shyamradhakrishnan shyamradhakrishnan changed the title Fix implicit aliasing issue in nested maps 🐛 Fix implicit aliasing issue in nested maps May 8, 2023
@@ -374,7 +374,8 @@ func (c *copyMethodMaker) genMapDeepCopy(actualName *namingInfo, mapType *types.
c.IfElse("val == nil", func() {
c.Line("(*out)[key] = nil")
}, func() {
c.Line("in, out := &val, &outVal")
c.Line("inVal := (*in)[key]")
c.Line("in, out := &inVal, &outVal")
Copy link
Member

Choose a reason for hiding this comment

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

Thank you a lot for the contribution 🥇
Could you please ensure that the change/issue is also covered with a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review @camilamacedo86 I have added a nested map in cronjob_types.go and that fields and other fields are calling this new line. I hope that will cover as a test case. Can you suggest if I need to add test cases in other places as well?

@shyamradhakrishnan
Copy link
Contributor Author

@vincepri @joelanford @camilamacedo86 gentle reminder for review

@gilbahat
Copy link

Hi, just ran into this as well. Looks fairly complete to me and 2 months passed, so maybe a gentle nudge is fair by now.

@shyamradhakrishnan
Copy link
Contributor Author

@vincepri @joelanford @camilamacedo86 gentle reminder for review

@sbueringer
Copy link
Member

Played a bit around with it. Works as expected

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer, shyamradhakrishnan

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 Aug 10, 2023
@k8s-ci-robot k8s-ci-robot merged commit d18ba5c into kubernetes-sigs:master Aug 10, 2023
LanceEa pushed a commit to emissary-ingress/emissary that referenced this pull request Sep 20, 2023
Two notable changes occurred with the generated
deep copy code:

1. Removed obsolete build tags
    - kubernetes-sigs/controller-tools#828

2. Fix implicit for loop aliasing
    - kubernetes-sigs/controller-tools#810

Signed-off-by: Lance Austin <[email protected]>
LanceEa pushed a commit to emissary-ingress/emissary that referenced this pull request Sep 20, 2023
Two notable changes occurred with the generated
deep copy code:

1. Removed obsolete build tags
    - kubernetes-sigs/controller-tools#828

2. Fix implicit for loop aliasing
    - kubernetes-sigs/controller-tools#810

Signed-off-by: Lance Austin <[email protected]>
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.

Nested maps deepcopy results in - Implicit memory aliasing in for loop - issue
5 participants