@@ -272,6 +272,12 @@ func (tmpl *Template) deleteListEntry(list string, idx int) {
272
272
tmpl .expr .WriteString (fmt .Sprintf ("| del($a.%s[%d], $b.%s[%d])\n " , list , idx , list , idx ))
273
273
}
274
274
275
+ // upgradeListEntryStringToMapField turns list[idx] from a string to a {field: list[idx]} map
276
+ func (tmpl * Template ) upgradeListEntryStringToMapField (list string , idx int , field string ) {
277
+ // TODO the head_comment on the string becomes duplicated as a foot_comment on the new field; could be a yq bug?
278
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.%s[%d] | select(type == \" !!str\" )) |= {\" %s\" : .}\n " , list , idx , field ))
279
+ }
280
+
275
281
// combineListEntries combines entries based on a shared unique key.
276
282
// If two entries share the same key, then any missing fields in the earlier entry are
277
283
// filled in from the latter one. The latter one is then deleted.
@@ -322,18 +328,26 @@ func (tmpl *Template) combineAdditionalDisks() {
322
328
}
323
329
}
324
330
for dst := from ; dst <= to ; dst ++ {
331
+ // upgrade additionalDisks[dst] from "disk" name string to {"name": "disk"} map so we can add fields
332
+ upgradeDiskToMap := sync .OnceFunc (func () {
333
+ tmpl .upgradeListEntryStringToMapField (additionalDisks , dst , "name" )
334
+ })
335
+
325
336
dest := & tmpl .Config .AdditionalDisks [dst ]
326
337
if dest .Format == nil && disk .Format != nil {
338
+ upgradeDiskToMap ()
327
339
tmpl .copyListEntryField (additionalDisks , dst , src , "format" )
328
340
dest .Format = disk .Format
329
341
}
330
342
// TODO: Does it make sense to merge "fsType" and "fsArgs" independently of each other?
331
343
if dest .FSType == nil && disk .FSType != nil {
344
+ upgradeDiskToMap ()
332
345
tmpl .copyListEntryField (additionalDisks , dst , src , "fsType" )
333
346
dest .FSType = disk .FSType
334
347
}
335
348
// "fsArgs" are inherited all-or-nothing; they are not appended
336
349
if len (dest .FSArgs ) == 0 && len (disk .FSArgs ) != 0 {
350
+ upgradeDiskToMap ()
337
351
tmpl .copyListEntryField (additionalDisks , dst , src , "fsArgs" )
338
352
dest .FSArgs = disk .FSArgs
339
353
}
0 commit comments