v24tov31: merge dropins and unit in case of duplicate#9
Conversation
| }, | ||
| { | ||
| Name: "kubeadm.service", | ||
| Enable: true, |
There was a problem hiding this comment.
One more test case is first having a drop-in, then having the service
translate/v24tov31/v24tov31.go
Outdated
| for _, unit := range cfg.Systemd.Units { | ||
| if _, isDup := unitMap[unit.Name]; isDup { | ||
| // If the unit name is duplicated and unit has no dropin, we raise an error. | ||
| if _, isDup := unitMap[unit.Name]; isDup && len(unit.Dropins) == 0 { |
There was a problem hiding this comment.
I would not look at whether this unit has a dropin but rather whether the units can be merged without conflict.
Merging works if the existing unit doesn't have a conflicting field. Then I would update the existing unit and add the new field(s).
Currently it looks like this would break if we first find a unit entry with a drop-in and then find the unit entry that enables it or that defines the content it.
There was a problem hiding this comment.
There is one more case that should work: multiple entries for a unit with different dropins, like this:
systemd:
units:
- name: etcd-member.service
dropins:
- name: dropin-1.conf
contents: |
droping-1
- name: etcd-member.service
dropins:
- name: dropin-2.conf
contents: |
droping-2There was a problem hiding this comment.
Thanks, I added this to the test case.
|
Nice work! |
| // We should only get one new unit from the merge. | ||
| if len(mergedUnits) == 1 { | ||
| // We override the previous unit with the new one for the next round. | ||
| unitsMap[u.Name] = mergedUnits[0] | ||
| continue | ||
| } |
There was a problem hiding this comment.
This could also be:
trUnit = mergedUnits[0]
(and the sanity check).
Ignition 3 does not handle duplicated systemd units (based on the unit name). We now use the `merge` package to merge the systemd units. Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
We can't really rely on existing tests as they test from Ign2 -> Ign3 and Ign3 -> Ign2 using the same configuration. The patch to fix the duplicated entries is not bijective between the two sets (Ign2 and Ign3) as we're merging configuration. Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
e09cae5 to
a5ba905
Compare
Signed-off-by: Mathieu Tortuyaux mtortuyaux@microsoft.com
Ignition 3 does not accept duplicated entries like:
{ "ignition": { "config": {}, "timeouts": {}, "version": "2.3.0" }, "networkd": {}, "passwd": {}, "storage": {}, "systemd": { "units": [ { "name": "extend-filesystems.service", "enable": true }, { "name": "extend-filesystems.service", "dropins": [ { "contents": "hello", "name": "10-flatcar.conf" } ], "enable": true } ] } }TODO: