-
Notifications
You must be signed in to change notification settings - Fork 226
Support nested Ignore.FieldPaths #119
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
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: chlunde 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 |
Hi @chlunde. Thanks for your PR. I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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/test-infra repository. |
pkg/model/model.go
Outdated
return | ||
} | ||
for sdkShapeID, shape := range m.SDKAPI.API.Shapes { | ||
ignoreFields: |
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.
I don't like this, I can extract this function later... 🌴
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.
@chlunde checkout this very similar function :) https://github.com/aws-controllers-k8s/code-generator/pull/78/files#diff-f5c09cb6b638098a0e513f710e901c9f7381165e4e2c49f2b3881613d2db518dR324 - the first implementation was using a goto
statement as well #78 (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.
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.
back from vacation today! I'll try to fix it by tomorrow
The current implementation of IgnoreFields did not support nested shapes. For Ignore.FieldPaths: Foo.Bar.Baz, it would ignore the whole of Bar. With this change, it supports multiple levels of nested fields. A practical example for this is ses CreateTemplateInput.Template.TemplateName. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
/ok-to-test |
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.
LGTM overall 👍 I left two comments below.
"Version", | ||
"ScalingConfig.DesiredSize", |
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.
Should'nt these be more Nodegroup.Version
and CreateNodegroupInput.ScalingConfig.DesiredSize
?
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.
This is already under getCRDByName("Nodegroup", ..)
, so logically it is now Nodegroup.ScalingConfig.DesiredSize
.
But yeah, if we could rewrite it to a unit test then maybe it would look like that, or maybe we should test it through another code path than getCRDByName
?
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset" | ||
"github.com/aws-controllers-k8s/code-generator/pkg/names" | ||
"github.com/aws-controllers-k8s/code-generator/pkg/util" | ||
awssdkmodel "github.com/aws/aws-sdk-go/private/model/api" |
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.
nit: goimports
can help with separating internal from external imports
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.
I think goimports
places it the same place, it was placed there by gopls
. I tried deleting the line and by running goimports -w ./pkg/model/model.go
I get the same result.
The sibling file
code-generator/pkg/model/field.go
Lines 19 to 22 in 2f11b23
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config" | |
"github.com/aws-controllers-k8s/code-generator/pkg/names" | |
"github.com/aws-controllers-k8s/code-generator/pkg/util" | |
awssdkmodel "github.com/aws/aws-sdk-go/private/model/api" |
# Test nested field path of multiple levels | ||
- Nodegroup.Version | ||
- CreateNodegroupInput.Version | ||
- CreateNodegroupInput.ScalingConfig.DesiredSize |
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.
Quoting from the docstring:
// Set of field paths to ignore. The name here should be the original name of
// the field as it appears in AWS SDK objects. You can refer to a field by
// giving its "<shape_name>.<field_name>". For example, "CreateApiInput.Name".
Would it be possible to use ScalingConfig.DesiredSize
(assuming ScalingConfig
is the name of the type) to achieve what you'd like?
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.
Yeah, that works 🤦 Thanks! :D
I was trying to help @ikarldasan on slack to get progress on crossplane-contrib/provider-aws#755 - but I didn't know how the generator config worked and dug into this hole.
So for that case, to ignore TemplateName, it would simply be:
ignore:
field_paths:
- Template.TemplateName
I though that was tested but apparently not :)
The current implementation of IgnoreFields did not support nested
shapes. For Ignore.FieldPaths: Foo.Bar.Baz, it would ignore the whole of
Bar.
With this change, it supports multiple levels of nested fields.
A practical example for this is ses CreateTemplateInput.Template.TemplateName.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.