Skip to content

allow SetFieldConfig.From to refer to nested fields #255

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

Merged
merged 2 commits into from
Jan 5, 2022

Conversation

jaypipes
Copy link
Collaborator

@jaypipes jaypipes commented 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.

IAM is used in tests in following patches, so add in the IAM API model
JSON file in a separate commit.

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

Signed-off-by: Jay Pipes <[email protected]>
@vijtrip2
Copy link
Contributor

vijtrip2 commented Jan 5, 2022

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 5, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Jan 5, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brycahta, jaypipes, vijtrip2

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:
  • OWNERS [brycahta,jaypipes,vijtrip2]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 82c294c into aws-controllers-k8s:main Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants