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

Use after-install && after-reset stages to initialize system #822

Merged
merged 3 commits into from
Aug 20, 2024

Conversation

anmazzotti
Copy link
Contributor

@anmazzotti anmazzotti commented Aug 15, 2024

Closes #806

The idea is that instead of generate several yip configs and pass them as ELEMENTAL_INSTALL_CLOUD_INIT list, we generate one single yip config to deterministically create the desired yip configs at desired locations. For example /oem/94_custom.yaml would always be /oem/elemental-network-config.yaml.

The after-install stage yip looks like the following (this sample only contains the registration config, the real one has all the other files):

name: Elemental Finalize System
stages:
    after-install:
        - files:
            - path: /run/elemental/oem/elemental-registration.yaml
              permissions: 384
              owner: 0
              group: 0
              content: |
                name: Include registration config into installed system
                stages:
                    initramfs:
                        - files:
                            - path: /oem/registration/config.yaml
                              permissions: 384
                              owner: 0
                              group: 0
                              content: |
                                elemental:
                                    registration:
                                        url: https://127.0.0.1.sslip.io/test/registration/endpoint
                                        ca-cert: a test ca
                                        emulate-tpm: true
                                        emulated-tpm-seed: 9876543210
                                        no-smbios: true
                                        auth: a test auth
                              encoding: ""
                              ownerstring: ""
                          if: '[ ! -f /oem/registration/config.yaml ]'
              encoding: ""
              ownerstring: ""
          directories:
            - path: /run/elemental/oem
              permissions: 448
              owner: 0
              group: 0
          name: Registration Config

I am not yet 100% sure that targeting /run/elemental/oem is the right thing to do during after-install or after-reset, but it does work.

@github-actions github-actions bot added area/operator operator related changes area/tests test related changes labels Aug 15, 2024
@anmazzotti anmazzotti force-pushed the use_after_install_reset_hooks branch from ff69404 to bd1a499 Compare August 16, 2024 09:28
@anmazzotti anmazzotti changed the title Use after-install|reset-chroot stage to initialize system Use after-install && after-reset stages to initialize system Aug 16, 2024
@anmazzotti anmazzotti force-pushed the use_after_install_reset_hooks branch from bd1a499 to bc5eaf5 Compare August 16, 2024 09:34
@anmazzotti anmazzotti force-pushed the use_after_install_reset_hooks branch from bc5eaf5 to df1961d Compare August 16, 2024 09:36
@anmazzotti
Copy link
Contributor Author

anmazzotti commented Aug 16, 2024

Still some issues with the after-reset hook.

The problem here is where to create the config, since:

  1. /system/oem and /usr/local/cloud-config are read only in recovery.
  2. /oem is formatted before the contents are evaluated

I think that adding /usr/local/cloud-config as ephemeral path in the recovery layout is a safe option to make this work.
/usr/local is by default a persistent path in the active system, but we don't mount any persistent path in recovery, so this solution would not collide with that (and with possible existing /usr/local/cloud-config/*.yaml files in the persistent partition) [Edit: Seems like mounting /usr/local/cloud-config in recovery breaks it, so this is not an option]

Another option would be to evaluate and cache all the /oem configs with after-reset* stages to be executed after formatting the OEM partition, but this feels a bit convoluted and hackish.

Probably the best solution would be to allow elemental-toolkit to consider dynamic config directories passed at runtime: elemental reset|install --evaluate-configs /tmp/my/custom/dir

@anmazzotti
Copy link
Contributor Author

This PR now depends on rancher/elemental-toolkit#2163

@anmazzotti anmazzotti marked this pull request as ready for review August 19, 2024 12:38
@anmazzotti anmazzotti requested a review from a team as a code owner August 19, 2024 12:38
@anmazzotti anmazzotti self-assigned this Aug 19, 2024
@anmazzotti anmazzotti merged commit 3de0fc7 into rancher:main Aug 20, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/operator operator related changes area/tests test related changes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Use elemental after-* hooks to install files on system
1 participant