Skip to content
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

Reference output_wrapper_field_path when generating CRD fields as part of the Create* request in model.go #210

Merged
merged 3 commits into from
Sep 29, 2021

Conversation

brycahta
Copy link
Contributor

Issue #, if available:

  • model.go does not take into account any output_wrapper_field_path overrides when processing Status fields for a CRD

Description of changes:

  • Refactored GetOutputShape api:
    • always return an output shape
    • make getWrapperOutputShape private
    • updated tests
  • Added GetOutputShape invocation to model.go so that overrides are checked before creating the CRD

Local Testing:

  • generator.yaml
operations:
  CreateVpcEndpoint:
    output_wrapper_field_path: VpcEndpoint
  • make build-controller SERVICE=ec2
  • Result: VPCEndpointStatus contains all unpacked fields. Assigning from aws sdk response (vpc_endpoint/sdk.go) includes resp.VpcEndpoint as prefix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.go does not take into account any output_wrapper_field_path overrides when processing Status fields for a CRD

I think what you're really referring to here is that model.go doesn't reference output_wrapper_field_path when generating CRD fields as part of the Create* request. I believe the code does use it in set_resource.sdk for Describe*.

Were you able to find a way for the adaptedSourceVarName to use the correct path?

Also it would be great to have a unit test for using GetOutputShape with Create*. That is, generating a list of Spec and Status fields and making sure it unwraps correctly (such as in your case with VpcEndpoint).

@@ -110,23 +110,14 @@ func SetResource(
if op == nil {
return ""
}
outputShape := op.OutputRef.Shape
outputShape, _ := r.GetOutputShape(op)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably want to handle this error, as it's critical. A panic might be a fair response if this returns an error - you cannot find the shape to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetOutputShape has a panic for that scenario. I kept logic consistent with previous behavior when refactoring

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the method does throw other errors apart from that panic.
I think it makes sense to catch error and panic
(OR ugly version would be to panic for all errors inside GetOutputShape and remove error from return type)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with catching error and panic for this. Throughout the code having a nil shape is not considered an error (ex: line 114 here), and I don't think it'd be correct to start doing so now.

Your suggestion with removing error return type sounds like the right way to go. However, I wouldn't panic for all errors just the scenario where there's a wrapper override that is expected to work. What do you guys think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough...
Since in the existing code outputshape is being returned as nil and then it is being handled in line 114, we do not need the error in method signature.

I would be onboard with removing error from method signature and keep the panic statement in method body

@brycahta
Copy link
Contributor Author

model.go does not take into account any output_wrapper_field_path overrides when processing Status fields for a CRD

I think what you're really referring to here is that model.go doesn't reference output_wrapper_field_path when generating CRD fields as part of the Create* request. I believe the code does use it in set_resource.sdk for Describe*.

You're right, that's clearer. I'll update PR title

Were you able to find a way for the adaptedSourceVarName to use the correct path?

Yessir, prior to these changes GetOutputShape would still try to unwrap a struct if it was the only member ref; however, I removed this because then the function would no longer be returning an OutputShape, but the nested field instead. Also, if no overrides are specified, GetOutputShape will return the original output shape,createOp.OutputRef.Shape.

Also it would be great to have a unit test for using GetOutputShape with Create*. That is, generating a list of Spec and Status fields and making sure it unwraps correctly (such as in your case with VpcEndpoint).

Good call, will add in next revision

Copy link
Contributor

@vijtrip2 vijtrip2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@brycahta brycahta changed the title Add wrapper field path overrides functionality to model.go Reference output_wrapper_field_path when generating CRD fields as part of the Create* request in model.go Sep 29, 2021
Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Sep 29, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brycahta, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 0466b01 into aws-controllers-k8s:main Sep 29, 2021
@jaypipes
Copy link
Collaborator

@brycahta in future, please do create a GH issue for tracking these kinds of issues and include in the GH issue a simple test that demonstrates the buggy behaviour.

if err != nil {
msg := fmt.Sprintf("Unable to unwrap the output shape: %v", err)
panic(msg)
}
sourceVarName += "." + *wrapperFieldPath
} else {
// If the wrapper field path is not specified in the config file and if
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but why didn't this block of code pick up the VpcEndpoint shape as being the wrapper struct?

Copy link
Contributor Author

@brycahta brycahta Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code works as intended. The issue was model.go:164 executed first and was not checking for overrides initially, and then code-generator would crash because it could not locate VpcEndpoint identifier.

I added GetOutputShape call here after refactoring to clean up the code a bit-- the logic remains the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to clarify that the original use for output_wrapper_field_path was working: You could unwrap a describe output structure into status and spec fields.

What we are adding in this is support for output_wrapper_field_path on a create output. That is, taking a wrapper structure from a create and creating new status and spec fields from its members. CreateVpcEndpointOutput has a wrapper of VpcEndpoint - its members are what we want in the spec and status for the CRD.

Some of the code changes @brycahta has made are re-using existing parts of the code that worked with the describe output to also work with create. I believe this is one of those elements.

@brycahta brycahta deleted the wrapper-fix branch September 30, 2021 18:31
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.

5 participants