-
Notifications
You must be signed in to change notification settings - Fork 203
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]>
brycahta
reviewed
Jan 5, 2022
brycahta
approved these changes
Jan 5, 2022
vijtrip2
approved these changes
Jan 5, 2022
/lgtm |
[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:
Approvers can indicate their approval by writing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thisparticular 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 theRole, the user specifies the PermissionsBoundary as an ARN field. In the
Create and Get Output shapes, however, the
PermissionsBoundary
fieldis a struct containing a
PermissionsBoundaryArn
string field. We wantto set the value of the Role resource's
Spec.PermissionsBoundary
fieldto the string value of this nested
PermissionsBoundary.PermissionsBoundaryArn
field. This patchfacilitates 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.