Skip to content

v24tov31: merge dropins and unit in case of duplicate#9

Merged
tormath1 merged 3 commits intomainfrom
tormath1/merge
Sep 26, 2022
Merged

v24tov31: merge dropins and unit in case of duplicate#9
tormath1 merged 3 commits intomainfrom
tormath1/merge

Conversation

@tormath1
Copy link
Copy Markdown
Collaborator

@tormath1 tormath1 commented Sep 9, 2022

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:

  • reword the commit

@tormath1 tormath1 self-assigned this Sep 9, 2022
@tormath1 tormath1 marked this pull request as ready for review September 9, 2022 16:06
@tormath1 tormath1 requested a review from a team September 9, 2022 16:07
},
{
Name: "kubeadm.service",
Enable: true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One more test case is first having a drop-in, then having the service

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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-2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I added this to the test case.

@tormath1
Copy link
Copy Markdown
Collaborator Author

@pothos @jepio thanks for the review. I took a new approach using the merge package from Ignition itself, we just need to wrap the duplicated units with Ignition Config but it should now cover most of the cases.

@jepio
Copy link
Copy Markdown
Member

jepio commented Sep 23, 2022

Nice work!

Comment on lines +366 to +371
// 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
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants