-
Notifications
You must be signed in to change notification settings - Fork 253
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
Errorneous generated code for ResolveReferences
for nested non array types
#1514
Closed
Vandita2020 opened this issue
Oct 18, 2022
· 3 comments
· Fixed by aws-controllers-k8s/code-generator#369
Closed
Errorneous generated code for ResolveReferences
for nested non array types
#1514
Vandita2020 opened this issue
Oct 18, 2022
· 3 comments
· Fixed by aws-controllers-k8s/code-generator#369
Labels
area/code-generation
Issues or PRs as related to controllers or docs code generation
kind/bug
Categorizes issue or PR as related to a bug.
priority/important-soon
Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Comments
/assign |
a-hilaly
changed the title
Missing if-else condition in generator
Errorneous generated code for ResolveReferences for nested non array types
Oct 18, 2022
a-hilaly
added
the
area/code-generation
Issues or PRs as related to controllers or docs code generation
label
Oct 18, 2022
a-hilaly
changed the title
Errorneous generated code for ResolveReferences for nested non array types
Errorneous generated code for Oct 18, 2022
ResolveReferences
for nested non array types
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
Oct 18, 2022
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Oct 21, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Oct 21, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Oct 24, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Oct 24, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Oct 24, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
ack-bot
pushed a commit
to aws-controllers-k8s/lambda-controller
that referenced
this issue
Oct 25, 2022
Description of changes: Adding functionality to the lambda controller to be able to reference Code.S3Bucket resource using resource references. This was generated using the patch aws-controllers-k8s/community#1514 is implemented. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Nov 1, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
a-hilaly
pushed a commit
to aws-controllers-k8s/code-generator
that referenced
this issue
Nov 4, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
Vandita2020
added a commit
to Vandita2020/ack-code-generator
that referenced
this issue
Dec 13, 2022
While generating the code for references for the Lambda function, more specifically for the S3 bucket field, we observe that there is use of array keywords with a non-array field e.g len(S3.Bucket) which is incorrect. After debugging code-generator, we observe that there was an incorrect piece of code (most likely becasue of copy paste) that considered nested parent field as an array. This patch fixes this issue by adding the right code for handling nested parent fields. Unfortunately we cannot add unit tests for this change because this part of the code generation resides inside the template and it's not a part of the pkg/generate/code package. Fixes aws-controllers-k8s/community#1514
Re-opening this issue because aws-controllers-k8s/code-generator#369 introduced a regression as detailed in |
As part of the refactoring references PR - aws-controllers-k8s/code-generator#417 - this issue seems to have gone away. When regenerating the // resolveReferenceForCode_S3Bucket reads the resource referenced
// from Code.S3BucketRef field and sets the Code.S3Bucket
// from referenced resource
func resolveReferenceForCode_S3Bucket(
ctx context.Context,
apiReader client.Reader,
namespace string,
ko *svcapitypes.Function,
) error {
if ko.Spec.Code == nil {
return nil
}
if ko.Spec.Code != nil {
if ko.Spec.Code.S3BucketRef != nil && ko.Spec.Code.S3BucketRef.From != nil {
arr := ko.Spec.Code.S3BucketRef.From
if arr == nil || arr.Name == nil || *arr.Name == "" {
return fmt.Errorf("provided resource reference is nil or empty: Code.S3BucketRef")
}
obj := &s3apitypes.Bucket{}
if err := getReferencedResourceState_Bucket(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
return err
}
ko.Spec.Code.S3Bucket = (*string)(obj.Spec.Name)
}
}
return nil
} |
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/bug
Categorizes issue or PR as related to a bug.
priority/important-soon
Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Describe the bug
While generating the code for references for the Lambda function, specifically more for the S3 bucket field, we observe that there is like use of array keywords with a non-array field which is like len(S3.Bucket) which is incorrect. While doing some debugging we found that there was some missing if-else conditions, a specific case where this should be handled.
Trying to run this code in lambda-controller/generator.yaml
This configuration instruct the code generator generate this line of code:
This most likely happening because of a missing/non discussed condition
{{ else if not $isList -}}
in https://github.com/aws-controllers-k8s/code-generator/blob/main/templates/pkg/resource/references.go.tpl#L146Steps to reproduce
Use the configuration above to generate code for
code.s3Bucket
referencesExpected outcome
Generate code that properly resolves references for nested non array types
Environment
The text was updated successfully, but these errors were encountered: