@@ -272,6 +272,12 @@ func (tmpl *Template) deleteListEntry(list string, idx int) {
272272 tmpl .expr .WriteString (fmt .Sprintf ("| del($a.%s[%d], $b.%s[%d])\n " , list , idx , list , idx ))
273273}
274274
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+
275281// combineListEntries combines entries based on a shared unique key.
276282// If two entries share the same key, then any missing fields in the earlier entry are
277283// filled in from the latter one. The latter one is then deleted.
@@ -322,18 +328,26 @@ func (tmpl *Template) combineAdditionalDisks() {
322328 }
323329 }
324330 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+
325336 dest := & tmpl .Config .AdditionalDisks [dst ]
326337 if dest .Format == nil && disk .Format != nil {
338+ upgradeDiskToMap ()
327339 tmpl .copyListEntryField (additionalDisks , dst , src , "format" )
328340 dest .Format = disk .Format
329341 }
330342 // TODO: Does it make sense to merge "fsType" and "fsArgs" independently of each other?
331343 if dest .FSType == nil && disk .FSType != nil {
344+ upgradeDiskToMap ()
332345 tmpl .copyListEntryField (additionalDisks , dst , src , "fsType" )
333346 dest .FSType = disk .FSType
334347 }
335348 // "fsArgs" are inherited all-or-nothing; they are not appended
336349 if len (dest .FSArgs ) == 0 && len (disk .FSArgs ) != 0 {
350+ upgradeDiskToMap ()
337351 tmpl .copyListEntryField (additionalDisks , dst , src , "fsArgs" )
338352 dest .FSArgs = disk .FSArgs
339353 }
0 commit comments