-
Notifications
You must be signed in to change notification settings - Fork 181
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
Correct the generated code for nested parent field reference. #369
Conversation
9a275d8
to
9727031
Compare
@@ -117,7 +117,7 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}( | |||
|
|||
{{- $fp := ConstructFieldPath $field.Path -}} | |||
{{ $_ := $fp.Pop -}} | |||
{{ $isNested := gt $fp.Size 0 -}} | |||
{{ $isNested := gt $fp.Size 0 -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind removing the whitespace at the end of this line please, @Vandita2020? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -143,6 +143,17 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}( | |||
} | |||
return nil | |||
} | |||
{{ else if not $isList -}} | |||
//is nested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a Go template comment instead of a Go comment:
{{/* nested field */}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -143,6 +143,17 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}( | |||
} | |||
return nil | |||
} | |||
{{ else if not $isList -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm mistaken, isNested
could be false
here.... so better to do this?
{{ if $isNested and (not $isList) -}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary, it is always going to be true here because of L132.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I missed that! :)
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
9727031
to
560c702
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+++
/test s3-controller-test |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, jaypipes, Vandita2020 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 |
@Vandita2020: The following tests failed, say
Full PR test history. Your PR dashboard. 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/test-infra repository. I understand the commands that are listed here. |
Merging as the test failure are related to gopkg.in issues (see niemeyer/gopkg#63) |
#398) Fixes aws-controllers-k8s/community#1653 Reverts #369 This pull request introduced a change to the way lists of references were accessed, but incorrectly falls back on a conditional that will treat a list of references as a struct. This breaks the `ec2` and `rds` controllers.
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect.
After debugging code-generator, we observe that there was an incorrect piece of code (most likely because of copy paste) that considered nested parent field as an array.
This patch fixes this issue by adding the right code for handling nested parent fields.
Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package.
Fixes aws-controllers-k8s/community#1514
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.