Skip to content

Commit 18745aa

Browse files
authored
Correct the generated code for nested parent field reference. (#369)
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 860408d commit 18745aa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

templates/pkg/resource/references.go.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}(
143143
}
144144
return nil
145145
}
146+
{{ else if not $isList -}}
147+
if ko.Spec.{{ $field.ReferenceFieldPath }} != nil &&
148+
ko.Spec.{{ $field.ReferenceFieldPath }}.From != nil {
149+
arr := ko.Spec.{{ $field.ReferenceFieldPath }}.From
150+
{{ template "read_referenced_resource_and_validate" $field }}
151+
referencedValue := string(*obj.{{ $field.FieldConfig.References.Path }})
152+
ko.Spec.{{ $field.Path }} = &referencedValue
153+
}
154+
return nil
155+
}
146156
{{ else }}
147157
{{ $parentField := index .CRD.Fields $fp.String }}
148158
{{ if eq $parentField.ShapeRef.Shape.Type "list" -}}

0 commit comments

Comments
 (0)