Skip to content

[code-gen] Unable to generate references.go for list of list of references #2478

Open
@michaelhtm

Description

@michaelhtm

Describe the bug
Currently Code-generator is not able to generate resource references for
List of list of References.

Here's a sample code:

func (rm *resourceManager) ClearResolvedReferences(res acktypes.AWSResource) acktypes.AWSResource {
	ko := rm.concreteResource(res).ko.DeepCopy()

	if ko.Spec.Serverless != nil {
		for f0idx, f0iter := range ko.Spec.Serverless.VPCConfigs {
			if len(f0iter.SecurityGroupRefs) > 0 {
				ko.Spec.Serverless.VPCConfigs.SecurityGroupIDs = nil
			}
		}
	}

	if ko.Spec.Serverless != nil {
		for f0idx, f0iter := range ko.Spec.Serverless.VPCConfigs {
			if len(f0iter.SubnetRefs) > 0 {
				ko.Spec.Serverless.VPCConfigs.SubnetIDs = nil
			}
		}
	}

	return &resource{ko}
}

Steps to reproduce
Sample generator.yaml for kafka-controller:

 ClusterV2:
    is_arn_primary_key: true
    renames:
      operations:
        CreateClusterV2:
          input_fields:
            ClusterName: Name
          output_fields:
            ClusteName: Name
            ClusterType: Type
        DescribeClusterV2:
          input_fields:
          output_fields:
            ClusterName: Name
            ClusterType: Type
    fields:
      ClusterARN:
        is_arn: true
      # TODO (michaelhtm) Fix generator of lists of list of references
      Serverless.VPCConfigs.SecurityGroupIDs:
        references:
          service_name: ec2
          resource: SecurityGroup
          path: Status.ID
      Serverless.VPCConfigs.SubnetIDs:
        references:
          service_name: ec2 
          resource: SubnetGroup
          path: Status.SubnetID

Expected outcome
Successfully generate Any type of references defined in generator.yaml
Here's the correct expected output:

func (rm *resourceManager) ClearResolvedReferences(res acktypes.AWSResource) acktypes.AWSResource {
	ko := rm.concreteResource(res).ko.DeepCopy()

	if ko.Spec.Serverless != nil {
		for f0idx, f0iter := range ko.Spec.Serverless.VPCConfigs {
			if len(f0iter.SecurityGroupRefs) > 0 {
				ko.Spec.Serverless.VPCConfigs[f0idx].SecurityGroupIDs = nil
			}
		}
	}

	if ko.Spec.Serverless != nil {
		for f0idx, f0iter := range ko.Spec.Serverless.VPCConfigs {
			if len(f0iter.SubnetRefs) > 0 {
				ko.Spec.Serverless.VPCConfigs[f0idx].SubnetIDs = nil
			}
		}
	}

	return &resource{ko}
}
  • code-generator version: 0.46.2
  • Using EKS (yes/no), if so version?
  • AWS service targeted (S3, RDS, etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationIssues or PRs as related to controllers or docs code generationarea/resource-referencesIssues or PRs related to resource references

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions