Skip to content
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

Correct the generated code for nested parent field reference. #369

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions templates/pkg/resource/references.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ func resolveReferenceFor{{ $field.FieldPathWithUnderscore }}(
}
return nil
}
{{ else if not $isList -}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, isNested could be false here.... so better to do this?

{{ if $isNested and (not $isList) -}}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary, it is always going to be true here because of L132.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I missed that! :)

if ko.Spec.{{ $field.ReferenceFieldPath }} != nil &&
ko.Spec.{{ $field.ReferenceFieldPath }}.From != nil {
arr := ko.Spec.{{ $field.ReferenceFieldPath }}.From
{{ template "read_referenced_resource_and_validate" $field }}
referencedValue := string(*obj.{{ $field.FieldConfig.References.Path }})
ko.Spec.{{ $field.Path }} = &referencedValue
}
return nil
}
{{ else }}
{{ $parentField := index .CRD.Fields $fp.String }}
{{ if eq $parentField.ShapeRef.Shape.Type "list" -}}
Expand Down