Skip to content

Commit

Permalink
Use after-install && after-reset stages to initialize system
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti committed Aug 16, 2024
1 parent d857bda commit bd1a499
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 232 deletions.
2 changes: 0 additions & 2 deletions pkg/elementalcli/elementalcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (r *runner) Reset(conf elementalv1.Reset) error {
func mapToInstallEnv(conf elementalv1.Install) []string {
var variables []string
// See GetInstallKeyEnvMap() in https://github.com/rancher/elemental-toolkit/blob/main/pkg/constants/constants.go
variables = append(variables, formatEV("ELEMENTAL_INSTALL_CLOUD_INIT", strings.Join(conf.ConfigURLs[:], ",")))
variables = append(variables, formatEV("ELEMENTAL_INSTALL_TARGET", conf.Device))
variables = append(variables, formatEV("ELEMENTAL_INSTALL_SYSTEM", conf.SystemURI))
variables = append(variables, formatEV("ELEMENTAL_INSTALL_FIRMWARE", conf.Firmware))
Expand All @@ -106,7 +105,6 @@ func mapToInstallEnv(conf elementalv1.Install) []string {
func mapToResetEnv(conf elementalv1.Reset) []string {
var variables []string
// See GetResetKeyEnvMap() in https://github.com/rancher/elemental-toolkit/blob/main/pkg/constants/constants.go
variables = append(variables, formatEV("ELEMENTAL_RESET_CLOUD_INIT", strings.Join(conf.ConfigURLs[:], ",")))
variables = append(variables, formatEV("ELEMENTAL_RESET_SYSTEM", conf.SystemURI))
variables = append(variables, formatEV("ELEMENTAL_RESET_PERSISTENT", strconv.FormatBool(conf.ResetPersistent)))
variables = append(variables, formatEV("ELEMENTAL_RESET_OEM", strconv.FormatBool(conf.ResetOEM)))
Expand Down
151 changes: 151 additions & 0 deletions pkg/install/_testdata/after-hook-config-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
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
network: {}
encoding: ""
ownerstring: ""
directories:
- path: /oem/registration
permissions: 448
owner: 0
group: 0
if: '[ ! -f /oem/registration/config.yaml ]'
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Registration Config
- files:
- path: /run/elemental/oem/elemental-state.yaml
permissions: 384
owner: 0
group: 0
content: |
name: Include registration state into installed system
stages:
initramfs:
- files:
- path: /oem/registration/state.yaml
permissions: 384
owner: 0
group: 0
content: |
initialRegistration: 2023-08-02T12:35:10.000000003Z
emulatedTPM: true
emulatedTPMSeed: 987654321
encoding: ""
ownerstring: ""
directories:
- path: /oem/registration
permissions: 448
owner: 0
group: 0
if: '[ ! -f /oem/registration/state.yaml ]'
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Registration State Config
- files:
- path: /run/elemental/oem/elemental-cloud-init.yaml
permissions: 384
owner: 0
group: 0
content: |
#cloud-config
users:
- name: root
passwd: root
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Cloud Init Config
- files:
- path: /run/elemental/oem/elemental-system-agent.yaml
permissions: 384
owner: 0
group: 0
content: |
name: Elemental System Agent Configuration
stages:
initramfs:
- files:
- path: /var/lib/elemental/agent/elemental_connection.json
permissions: 384
owner: 0
group: 0
content: '{"kubeConfig":"apiVersion: v1\nclusters:\n- cluster:\n certificate-authority-data: YSB0ZXN0IGNh\n server: https://127.0.0.1.sslip.io/test/control/plane/endpoint\n name: cluster\ncontexts:\n- context:\n cluster: cluster\n user: user\n name: context\ncurrent-context: context\nkind: Config\npreferences: {}\nusers:\n- name: user\n user:\n token: a test token\n","namespace":"a test namespace","secretName":"a test secret name"}'
encoding: ""
ownerstring: ""
- path: /etc/rancher/elemental/agent/config.yaml
permissions: 384
owner: 0
group: 0
content: |
workDirectory: /var/lib/elemental/agent/work
localPlanDirectory: /var/lib/elemental/agent/plans
appliedPlanDirectory: /var/lib/elemental/agent/applied
remoteEnabled: true
connectionInfoFile: /var/lib/elemental/agent/elemental_connection.json
encoding: ""
ownerstring: ""
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Elemental System Agent Config
- files:
- path: /run/elemental/oem/elemental-network.yaml
permissions: 384
owner: 0
group: 0
content: |
name: Test Network Config Applicator
stages:
foo:
- commands:
- bar
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Network Config
151 changes: 151 additions & 0 deletions pkg/install/_testdata/after-hook-config-reset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: Elemental Finalize System
stages:
after-reset:
- 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
network: {}
encoding: ""
ownerstring: ""
directories:
- path: /oem/registration
permissions: 448
owner: 0
group: 0
if: '[ ! -f /oem/registration/config.yaml ]'
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Registration Config
- files:
- path: /run/elemental/oem/elemental-state.yaml
permissions: 384
owner: 0
group: 0
content: |
name: Include registration state into installed system
stages:
initramfs:
- files:
- path: /oem/registration/state.yaml
permissions: 384
owner: 0
group: 0
content: |
initialRegistration: 2023-08-02T12:35:10.000000003Z
emulatedTPM: true
emulatedTPMSeed: 987654321
encoding: ""
ownerstring: ""
directories:
- path: /oem/registration
permissions: 448
owner: 0
group: 0
if: '[ ! -f /oem/registration/state.yaml ]'
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Registration State Config
- files:
- path: /run/elemental/oem/elemental-cloud-init.yaml
permissions: 384
owner: 0
group: 0
content: |
#cloud-config
users:
- name: root
passwd: root
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Cloud Init Config
- files:
- path: /run/elemental/oem/elemental-system-agent.yaml
permissions: 384
owner: 0
group: 0
content: |
name: Elemental System Agent Configuration
stages:
initramfs:
- files:
- path: /var/lib/elemental/agent/elemental_connection.json
permissions: 384
owner: 0
group: 0
content: '{"kubeConfig":"apiVersion: v1\nclusters:\n- cluster:\n certificate-authority-data: YSB0ZXN0IGNh\n server: https://127.0.0.1.sslip.io/test/control/plane/endpoint\n name: cluster\ncontexts:\n- context:\n cluster: cluster\n user: user\n name: context\ncurrent-context: context\nkind: Config\npreferences: {}\nusers:\n- name: user\n user:\n token: a test token\n","namespace":"a test namespace","secretName":"a test secret name"}'
encoding: ""
ownerstring: ""
- path: /etc/rancher/elemental/agent/config.yaml
permissions: 384
owner: 0
group: 0
content: |
workDirectory: /var/lib/elemental/agent/work
localPlanDirectory: /var/lib/elemental/agent/plans
appliedPlanDirectory: /var/lib/elemental/agent/applied
remoteEnabled: true
connectionInfoFile: /var/lib/elemental/agent/elemental_connection.json
encoding: ""
ownerstring: ""
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Elemental System Agent Config
- files:
- path: /run/elemental/oem/elemental-network.yaml
permissions: 384
owner: 0
group: 0
content: |
name: Test Network Config Applicator
stages:
foo:
- commands:
- bar
encoding: ""
ownerstring: ""
directories:
- path: /run/elemental/oem
permissions: 448
owner: 0
group: 0
name: Network Config
4 changes: 0 additions & 4 deletions pkg/install/_testdata/cloud-init-config.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/install/_testdata/network-config-applicator.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/install/_testdata/registration-config-config.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions pkg/install/_testdata/registration-state-config.yaml

This file was deleted.

Loading

0 comments on commit bd1a499

Please sign in to comment.