Skip to content

Handle nested fields in SetFieldConfig #1065

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

Closed
jaypipes opened this issue Nov 12, 2021 · 5 comments
Closed

Handle nested fields in SetFieldConfig #1065

jaypipes opened this issue Nov 12, 2021 · 5 comments
Assignees
Labels
area/code-generation Issues or PRs as related to controllers or docs code generation kind/enhancement Categorizes issue or PR as related to existing feature enhancements. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.

Comments

@jaypipes
Copy link
Collaborator

While implementing the solution for #178, Bryan pointed out that the solution would not work for nested field paths.

We should address this gap in functionality.

@jaypipes jaypipes added kind/enhancement Categorizes issue or PR as related to existing feature enhancements. area/code-generation Issues or PRs as related to controllers or docs code generation labels Nov 12, 2021
@a-hilaly a-hilaly added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Nov 19, 2021
ack-bot pushed a commit to aws-controllers-k8s/code-generator that referenced this issue Jan 5, 2022
Often, the Go type of a Create Input shape field (which goes in the
resource's Spec struct) is different from the Go type of the same-named
field in an Output shape. This causes problems for the code generator,
which doesn't know how to set the value of the Spec field due to these
different source and target Go types.

The `pkg/generate/config.SetConfig` struct was designed to solve this
particular issue, however the original solution only worked properly
when the field in the Output shape that we wanted to set the Spec field
*from* was at the same "level" as the field we wanted to set the value
*to*.

Take for example the case of the IAM Role resource, which has a Create
Input shape with a string `PermissionsBoundary` field. When creating the
Role, the user specifies the PermissionsBoundary as an ARN field. In the
Create and Get Output shapes, however, the `PermissionsBoundary` field
is a struct containing a `PermissionsBoundaryArn` string field. We want
to set the value of the Role resource's `Spec.PermissionsBoundary` field
to the string value of this nested
`PermissionsBoundary.PermissionsBoundaryArn` field. This patch
facilitates that by modifying the `pkg/generate/code.SetResource`
function to look up the field in the Output shape via a field path
instead of a single field name map lookup.

Issue aws-controllers-k8s/community#1065

Signed-off-by: Jay Pipes <[email protected]>

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
@jaypipes jaypipes self-assigned this Jan 14, 2022
jaypipes added a commit to jaypipes/ack-code-generator that referenced this issue Jan 14, 2022
A previous commit added functionality to the API/resource inference
process to "unpack" a struct field's member fields into the
`pkg/model.Field.MemberFields` map. However, I had failed to account for
lists or maps of structs. This patch accounts for the list or map of
structs fields, stepping into the list field's element struct type and
adding a Field definition to the containing Field's `MemberFields` map
for each member field in the element struct type. Same for containing
shapes of type "map".

With this patch, we're now able to "access" via field path any nested
field (including its corresponding `FieldConfig` object) which means
that in following patches we can finally resolve the "different Go types
for nested fields" problem we've had in the code generator.

Related issue: aws-controllers-k8s/community#1065

Signed-off-by: Jay Pipes <[email protected]>
@a-hilaly
Copy link
Member

/assign @brycahta

@ack-bot
Copy link
Collaborator

ack-bot commented Jan 28, 2022

@a-hilaly: GitHub didn't allow me to assign the following users: brycahta.

Note that only aws-controllers-k8s members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @brycahta

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.

@a-hilaly
Copy link
Member

/assign @brycahta

@RedbackThomson
Copy link
Contributor

@brycahta Is there work left to do for this?

@brycahta
Copy link
Contributor

@RedbackThomson No work left.

I was going to resolve once we cut a release with these changes/fixes. If y'all have a different process feel free to resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Issues or PRs as related to controllers or docs code generation kind/enhancement Categorizes issue or PR as related to existing feature enhancements. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Projects
None yet
Development

No branches or pull requests

5 participants