Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable extensions for kairos-init #23

Merged
merged 3 commits into from
Mar 4, 2025
Merged

Enable extensions for kairos-init #23

merged 3 commits into from
Mar 4, 2025

Conversation

Itxaka
Copy link
Member

@Itxaka Itxaka commented Mar 4, 2025

This allows to load stage extensions from a dir in the filesystem to expand the default stages with custom logic.
You can enable this feature by using the --stage-extensions flag

The structure is as follows:
We got a base dir which is /etc/kairos-init/stage-extensions (this is the default, but you can override it using the KAIROS_INIT_STAGE_EXTENSIONS_DIR env var)
You can drop your custom yip files and as usual, they will be loaded and executed in lexicographic order.

So for example, if we have:

  • /etc/kairos-init/stage-extensions/10-foo.yaml
  • /etc/kairos-init/stage-extensions/20-bar.yaml
  • /etc/kairos-init/stage-extensions/30-baz.yaml

The files will be loaded in the following order:

  • 10-foo.yaml
  • 20-bar.yaml
  • 30-baz.yaml

The files are loaded using the yip library, so you can use all the features of yip to expand the stages.
The current stages available are:

  • before-install: Good for adding extra repos and such.
  • install: Good for installing packages and such.
  • after-install: Do some cleanup of packages, add extra packages, add different kernels and remove the kairos default one, etc.
  • before-init: Good for adding some dracut modules for example to be added to the initramfs.
  • init: Anything that configures the system, security hardening for example.
  • after-init: Good for rebuilding the initramfs, or adding a different initramfs like a kdump one, add grub configs or branding, etc.

So for example, if we were to add an extra repo for zfs and install the package we could do the following:
/etc/kairos-init/stage-extensions/10-zfs.yaml

stages:
  after-install:
    - files:
        - path: /etc/apt/sources.list.d/zfs.list
          permissions: 0644
          owner: 0
          group: 0
          content: |
            deb http://deb.debian.org/debian bookworm-backports main contrib
            deb-src http://deb.debian.org/debian bookworm-backports main contrib
    - packages:
        install:
          - "zfs-dkms"
          - "zfsutils-linux"
        refresh: true

This would run the before-install and install stages as normal, but then on the after-install stage it would add the zfs repo and install the zfs packages.

See readme for more info

Signed-off-by: Itxaka <[email protected]>
@Itxaka Itxaka requested a review from a team March 4, 2025 11:28
Copy link

@jimmykarily jimmykarily left a comment

Choose a reason for hiding this comment

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

Having an implicit default directory (with no configuration passed) could result in forgotten files being used and people reporting bugs because they didn't cleanup that directory. I feel we should make this an explicit (and only explicit) option in kairos-init to make sure people actually meant to use the expansions.

@Itxaka
Copy link
Member Author

Itxaka commented Mar 4, 2025

Having an implicit default directory (with no configuration passed) could result in forgotten files being used and people reporting bugs because they didn't cleanup that directory. I feel we should make this an explicit (and only explicit) option in kairos-init to make sure people actually meant to use the expansions.

Well it requires a explicit COPY to copy the expansion files but yeah, it makes sense to hide this under a flag. I tried to make it as stroighforward as possible as I think the flags are growing way too much already adn I prefer it to be simpler, but yeah will add it like that

@jimmykarily
Copy link

jimmykarily commented Mar 4, 2025

Having an implicit default directory (with no configuration passed) could result in forgotten files being used and people reporting bugs because they didn't cleanup that directory. I feel we should make this an explicit (and only explicit) option in kairos-init to make sure people actually meant to use the expansions.

Well it requires a explicit COPY to copy the expansion files but yeah, it makes sense to hide this under a flag. I tried to make it as stroighforward as possible as I think the flags are growing way too much already adn I prefer it to be simpler, but yeah will add it like that

An alternative would be to print out a message (warning) that there are files in the default directory and that they are going to be used. In that case, I would change the path from /tmp to something else (/etc ?). Because tmp is neither guaranteed to be emptied nor to be persisted. It always depends on the machine's setup.

This way, if anyone reports bugs, we will at least see that message in the logs they share without having to ask them to check if there is anything in that path.

@Itxaka Itxaka merged commit de5380e into main Mar 4, 2025
19 checks passed
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.

2 participants