Skip to content

Errorneous generated code for ResolveReferences for nested non array types #1514

@Vandita2020

Description

@Vandita2020

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

resources:
  Function:
    fields:
      Code.S3Bucket:
        references:
          resource: Bucket
          path: Spec.Name
          service_name: s3

This configuration instruct the code generator generate this line of code:

    // This doesn't work because s3BucketRef is not an array
    len(ko.Spec.Code.S3BucketRef) > 0

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#L146

Steps to reproduce
Use the configuration above to generate code for code.s3Bucket references

Expected outcome
Generate code that properly resolves references for nested non array types

Environment

  • Kubernetes version
  • Using EKS (yes/no), if so version?
  • AWS service targeted (S3, RDS, etc.)

Metadata

Metadata

Assignees

Labels

area/code-generationIssues or PRs as related to controllers or docs code generationkind/bugCategorizes issue or PR as related to a bug.priority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions