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

fix(Cloudfront): LateInit missing fields #1298

Merged
merged 1 commit into from
May 11, 2022

Conversation

ezgidemirel
Copy link
Contributor

Signed-off-by: ezgidemirel [email protected]

Description of your changes

This PR late initializes ResponseHeadersPolicyID and FunctionAssociation fields.

Fixes #1295

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Created a distribution with ResponseHeadersPolicyID.

NAME                                                                              READY   SYNCED   EXTERNAL-NAME
responseheaderspolicy.cloudfront.aws.crossplane.io/ezgi-response-headers-policy   True    True     7cfa4a57-984a-4985-8ea7-4dcdecb9750f
NAME                                                                           READY   SYNCED   EXTERNAL-NAME
distribution.cloudfront.aws.crossplane.io/example-distribution-custom-origin   True    True     E27DGUZ2ZA71OI

continue
}
// FunctionARN must be unique for each FunctionAssociation
existing[awsclients.StringValue(o.FunctionARN)] = o
Copy link
Contributor

Choose a reason for hiding this comment

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

We have checked the API reference and the console UI for cache behavior with @ezgidemirel. It looks like the key for this resource should be the event type.

Comment on lines 760 to 762
if o.FunctionARN == nil {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see the comment below regarding the chosen key. We would not expect the key type to be a pointer but although in the console UI, it's not a pointer type, the SDK expects a pointer type. We did not check what happens if you call the SDK function with a nil EventType but from what we observed from the console UI, this should not be allowed.

Suggested change
if o.FunctionARN == nil {
continue
}

Copy link
Contributor Author

@ezgidemirel ezgidemirel May 11, 2022

Choose a reason for hiding this comment

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

As expected, AWS doesn't allow EventType to be nil. Removing this nil check caused following error:

    message: "update failed: cannot update Distribution in AWS: PreconditionFailed:
      The request failed because it didn't meet the preconditions in one or more request-header
      fields.\n\tstatus code: 412, request id: "

I added back with the EventType.

continue
}
// FunctionARN must be unique for each FunctionAssociation
existing[awsclients.StringValue(o.FunctionARN)] = o
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
existing[awsclients.StringValue(o.FunctionARN)] = o
existing[awsclients.StringValue(o.EventType)] = o

}

for _, il := range in.Items {
if il.FunctionARN == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if il.FunctionARN == nil {
if il.EventType != nil {

continue
}

fl := existing[awsclients.StringValue(il.FunctionARN)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fl := existing[awsclients.StringValue(il.FunctionARN)]
fl := existing[awsclients.StringValue(il.EventType)]

Copy link
Contributor

@ulucinar ulucinar left a comment

Choose a reason for hiding this comment

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

Thank you @ezgidemirel. We may consider opening a separate bug to track the issue spotted for the LambdaFunctionAssociations.

// If we have some lambda function associations, we need to late init each one of them
existing := make(map[string]*svcsdk.LambdaFunctionAssociation)
for i := range from.Items {
o := from.Items[i]
if o.LambdaFunctionARN == nil {
continue
}
// TODO(ezgidemirel): Instead of using FunctionARNs, we should use EventTypes as keys
Copy link
Contributor

@ulucinar ulucinar May 11, 2022

Choose a reason for hiding this comment

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

We may consider opening a bug in the repo. We may also consider switching back to dynamic late initialization.

@ulucinar ulucinar merged commit aab494e into crossplane-contrib:master May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloudfront Distribution resource doesn't become ready when ResponseHeadersPolicyID is set
2 participants