-
Notifications
You must be signed in to change notification settings - Fork 226
Allow calling GoCodeSetResourceForStruct for non-CRD SDK shapes
#387
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
Allow calling GoCodeSetResourceForStruct for non-CRD SDK shapes
#387
Conversation
GoCodeSetResourceForStruct for non-CRD fieldsGoCodeSetResourceForStruct for non-CRD fields
GoCodeSetResourceForStruct for non-CRD fieldsGoCodeSetResourceForStruct for non-CRD shapes
GoCodeSetResourceForStruct for non-CRD shapesGoCodeSetResourceForStruct for non-CRD SDK shapes
|
I don't think I understand how this solves the problem? This seems to be throwing away error handling, but I don't see how it's able to access fields that aren't in the spec or status? It still uses |
Because the statement bellow will not return a positive f, ok := r.Fields[targetFieldName]
if !ok {
return ""
}Reading the code again i just realized that i need to add the |
| assert.Equal( | ||
| expected, | ||
| code.SetResourceForStruct( | ||
| crd.Config(), crd, "", "krTarget", krTargetShape, nil, "sdkTarget", sdkTargetShape, "", model.OpTypeList, 1, |
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.
All of the other calls in this test file use "resp" and "ko" for the SDK and Kubernetes object variable names, respectively. Can we match that?
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.
The thing is that Target is not a CRD nor a CRD Field - There is no need to use resp and ko as they really represent what the function is used for
| krTarget.ARN = sdkTarget.Arn | ||
| } | ||
| if sdkTarget.BatchParameters != nil { | ||
| krTargetf1 := &svcapitypes.BatchParameters{} |
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.
Normally, this would just be:
f1 := &svcapitypes.BatchParameters{}not
krTargetf1 := &svcapitypes.BatchParameters{}I think you are incorrectly specifying the target variable name...
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.
The thing is if i change krTarget to an empty string, L3298 will become .ARN = resp.Arn which is not correct
63caf60 to
f09171b
Compare
|
/retest |
|
Pinging @a-hilaly for who can review and LGTM since this is blocking the ACK EventBridge controller 🙏🏻 |
|
Setting the test naming conventions aside, I am happy with this as a simple feature/fix. |
|
/approve |
f09171b to
215b1b9
Compare
| ko.DeadLetterConfig = kof2 | ||
| } | ||
| if resp.EcsParameters != nil { | ||
| kof3 := &svcapitypes.EcsParameters{} |
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.
Hmm, this should be ECSParameters... we need to add ECS to the initialisms.
| kof3.CapacityProviderStrategy = kof3f0 | ||
| } | ||
| if resp.EcsParameters.EnableECSManagedTags != nil { | ||
| kof3.EnableECSManagedTags = resp.EcsParameters.EnableECSManagedTags |
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.
Interesting that they used "ECS" instead of "Ecs" in this field name...
| assert.Equal( | ||
| expected, | ||
| code.SetResourceForStruct( | ||
| crd.Config(), crd, "", "ko", koShape, nil, "resp", targetShape, "", model.OpTypeList, 1, |
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.
Turns out that the targetField parameter isn't ever used by the SetResourceForStruct function :( Only the targetFieldPath parameter is ever used.
My request is that you:
- remove the unused
targetFieldparameter (since it is just confusing) from theSetResourceForStructfunction - Pass
fXfor the targetVarName parameter (normally this would be something like "f12" ifSetResourceForStructis being called recursively from other functions inpkg/generate/code/set_resource.goor it would be the name of the field ifSetResourceForStructwas called from a top-level template insdk_file_endhooks...)
Previously, the code-generator was unable to use `GoCodeSetResourceForStruct` for fields that are not part of a CRD spec or status. This caused issues when trying to generate custom code that transforms an eventbridge `v1alpha1.Target` to an `svcsdk.Target`. This patch fixes the issue by allowing users to call `GoCodeSetResourceForStruct` for any field, not just CRD top level fields. In addition, unit tests have been added to ensure the correct behavior. Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
215b1b9 to
1ab64e5
Compare
jaypipes
left a comment
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.
Much better. Thank you sir! :)
|
/retest |
2 similar comments
|
/retest |
|
/retest |
|
/test all |
|
/retest |
|
/test all |
1 similar comment
|
/test all |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, jaypipes, jljaco, RedbackThomson 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 |
Issue: aws-controllers-k8s/community#1609
Previously, the code-generator was unable to let us use
GoCodeSetResourceForStructfor fields that are not part of a CRD top level fields. This caused issues when trying to generate custom code that transforms an eventbridgev1alpha1.Targetto ansvcsdk.Target.This patch fixes the issue by allowing users to call
GoCodeSetResourceForStructfor any field, not just CRD top level fields. In addition, unit tests have been added to ensure the correct behavior.This patch is needed to allow us to properly execute the template written here https://github.com/embano1/eventbridge-controller/blob/aminemicha/templates/hooks/rule/sdk_file_end.go.tpl
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.