@@ -255,9 +255,8 @@ func ResolveReferencesForField(field *model.Field, sourceVarName string, indentL
255
255
outPrefix += fmt .Sprintf ("%s\t \t return fmt.Errorf(\" provided resource reference is nil or empty: %s\" )\n " , indent , field .ReferenceFieldPath ())
256
256
outPrefix += fmt .Sprintf ("%s\t }\n " , indent )
257
257
258
- outPrefix += fmt .Sprintf ("%s\t if err := getReferencedResourceState_%s(ctx, apiReader, obj, *arr.Name, namespace); err != nil {\n " , indent , field .FieldConfig .References .Resource )
259
- outPrefix += fmt .Sprintf ("%s\t \t return err\n " , indent )
260
- outPrefix += fmt .Sprintf ("%s\t }\n " , indent )
258
+ outPrefix += getReferencedStateForField (field , indentLevel + idx )
259
+
261
260
outPrefix += fmt .Sprintf ("%s\t %s = append(%s, obj.%s)\n " , indent , targetVarName , targetVarName , field .FieldConfig .References .Path )
262
261
outPrefix += fmt .Sprintf ("%s}\n " , indent )
263
262
case ("map" ):
@@ -272,14 +271,8 @@ func ResolveReferencesForField(field *model.Field, sourceVarName string, indentL
272
271
outPrefix += fmt .Sprintf ("%s\t \t return fmt.Errorf(\" provided resource reference is nil or empty: %s\" )\n " , indent , field .ReferenceFieldPath ())
273
272
outPrefix += fmt .Sprintf ("%s\t }\n " , indent )
274
273
275
- if field .FieldConfig .References .ServiceName == "" {
276
- outPrefix += fmt .Sprintf ("%s\t obj := &svcapitypes.%s{}\n " , indent , field .FieldConfig .References .Resource )
277
- } else {
278
- outPrefix += fmt .Sprintf ("%s\t obj := &%sapitypes.%s{}\n " , indent , field .ReferencedServiceName (), field .FieldConfig .References .Resource )
279
- }
280
- outPrefix += fmt .Sprintf ("%s\t if err := getReferencedResourceState_%s(ctx, apiReader, obj, *arr.Name, namespace); err != nil {\n " , indent , field .FieldConfig .References .Resource )
281
- outPrefix += fmt .Sprintf ("%s\t \t return err\n " , indent )
282
- outPrefix += fmt .Sprintf ("%s\t }\n " , indent )
274
+ outPrefix += getReferencedStateForField (field , indentLevel + idx )
275
+
283
276
outPrefix += fmt .Sprintf ("%s\t %s = (%s)(obj.%s)\n " , indent , targetVarName , field .GoType , field .FieldConfig .References .Path )
284
277
outPrefix += fmt .Sprintf ("%s}\n " , indent )
285
278
}
@@ -288,6 +281,22 @@ func ResolveReferencesForField(field *model.Field, sourceVarName string, indentL
288
281
return outPrefix + outSuffix
289
282
}
290
283
284
+ func getReferencedStateForField (field * model.Field , indentLevel int ) string {
285
+ out := ""
286
+ indent := strings .Repeat ("\t " , indentLevel )
287
+
288
+ if field .FieldConfig .References .ServiceName == "" {
289
+ out += fmt .Sprintf ("%s\t obj := &svcapitypes.%s{}\n " , indent , field .FieldConfig .References .Resource )
290
+ } else {
291
+ out += fmt .Sprintf ("%s\t obj := &%sapitypes.%s{}\n " , indent , field .ReferencedServiceName (), field .FieldConfig .References .Resource )
292
+ }
293
+ out += fmt .Sprintf ("%s\t if err := getReferencedResourceState_%s(ctx, apiReader, obj, *arr.Name, namespace); err != nil {\n " , indent , field .FieldConfig .References .Resource )
294
+ out += fmt .Sprintf ("%s\t \t return err\n " , indent )
295
+ out += fmt .Sprintf ("%s\t }\n " , indent )
296
+
297
+ return out
298
+ }
299
+
291
300
func nestedStructNilCheck (path fieldpath.Path , fieldAccessPrefix string ) string {
292
301
out := ""
293
302
fieldNamePrefix := ""
0 commit comments