Skip to content

Commit 9a275d8

Browse files
committed
Correct the generated code for nested parent field reference.
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
1 parent 21c6d42 commit 9a275d8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

templates/pkg/resource/references.go.tpl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}(
117117

118118
{{- $fp := ConstructFieldPath $field.Path -}}
119119
{{ $_ := $fp.Pop -}}
120-
{{ $isNested := gt $fp.Size 0 -}}
120+
{{ $isNested := gt $fp.Size 0 -}}
121121
{{ $isList := eq $field.ShapeRef.Shape.Type "list" -}}
122122
{{ if and (not $isList) (not $isNested) -}}
123123
if ko.Spec.{{ $field.ReferenceFieldPath }} != nil &&
@@ -168,15 +168,11 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}(
168168
}
169169
{{ else -}}
170170
if ko.Spec.{{ $field.ReferenceFieldPath }} != nil &&
171-
len(ko.Spec.{{ $field.ReferenceFieldPath }}) > 0 {
172-
resolvedReferences := []*string{}
173-
for _, arrw := range ko.Spec.{{ $field.ReferenceFieldPath }} {
174-
arr := arrw.From
171+
ko.Spec.{{ $field.ReferenceFieldPath }}.From != nil {
172+
arr := ko.Spec.{{ $field.ReferenceFieldPath }}.From
175173
{{ template "read_referenced_resource_and_validate" $field }}
176-
referencedValue := string(*obj.{{ $field.FieldConfig.References.Path }})
177-
resolvedReferences = append(resolvedReferences, &referencedValue)
178-
}
179-
ko.Spec.{{ $field.Path }} = resolvedReferences
174+
referencedValue := string(*obj.{{ $field.FieldConfig.References.Path }})
175+
ko.Spec.{{ $field.Path }} = &referencedValue
180176
}
181177
return nil
182178
}

0 commit comments

Comments
 (0)