host-containers: migrate to use config file
Issue number:
Closes #3627
Description of changes:
Removes dependency on the API model from host-containers by changing it to use a config file rendered from the settings.
Testing done:
Built an aws-dev variant with my changes and tested that changes to the host-containers settings behaved as expected. The admin container started with my provided user data, and I was able to add a new test host container.
TODO: test that the migrations behave as expected
Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.
^ update template to {{{ everything to keep it consistent with what we expected when reading directly from the API
^ address @webern's comments
^ testing summary:
-
[x] Ran
cargo +nightly udepsto ensure all unused dependencies have been removed -
[x] Pass the settings on first boot via userdata. Verify config.
Enabled and configured the admin container in user data.
cat'd the config file at/etc/host-containers/host-containers.tomland it contained the user data. -
[x] cat /etc/os-release record your build ID include commit sha, record this
bash-5.1# cat /etc/os-release
...
VERSION="1.19.3 (aws-dev)"
...
BUILD_ID=1e9e8f3a
...
- [x] Use apiclient to update relevant settings at runtime. Verify config was updated correctly.
bash-5.1# apiclient set --json '{"settings": {"host-containers": {"foo": {"source": "public.ecr.aws/bottlerocket/bottlerocket-admin:v0.11.5", "enabled": true, "superpowered": true}}}}'
bash-5.1# cat /etc/host-containers/host-containers.toml
...
[host-containers."foo"]
source = "public.ecr.aws/bottlerocket/bottlerocket-admin:v0.11.5"
enabled = true
superpowered = true
- [x] Downgrade to older version.
- [x] verify connectivity
- [x] cat /etc/os-release to verify lower version
- [x] verify that migrations have changed the metadata/settings as expected (i.e. they are gone from the datastore, or lists have been changed back)
bash-5.1# updog update -i 1.19.2 -r -n
Starting update to 1.19.2
Reboot scheduled for Wed 2024-03-06 01:53:29 UTC, use 'shutdown -c' to cancel.
Update applied: aws-dev 1.19.2
# after reboot, was able to ssh successfully
bash-5.1# cat /etc/os-release
...
VERSION="1.19.2 (aws-dev)"
...
# no host-containers-toml config file, and it is removed from host-containers config files
bash-5.1# ls /var/lib/bottlerocket/datastore/current/live/configuration-files/
certdog-toml containerd-config-toml hostname metricdog-toml motd proxy-env
cfsignal-toml docker-daemon-config hosts modprobe-conf netdog-toml updog-toml
chrony-conf host-ctr-toml log4j-hotpatch-enabled-log-message modules-load oci-hooks
bash-5.1# cat /var/lib/bottlerocket/datastore/current/live/services/host-containers/configuration-files
["host-ctr-toml"]
- [x] Upgrade to newer version.
- [x] verify connectivity
- [x] cat /etc/os-release to verify version
- [x] verify config file
bash-5.1# updog update -i 1.19.3 -r -n
Starting update to 1.19.3
Reboot scheduled for Wed 2024-03-06 01:58:04 UTC, use 'shutdown -c' to cancel.
Update applied: aws-dev 1.19.3
# after reboot, was able to ssh successfully
bash-5.1# cat /etc/os-release
...
VERSION="1.19.3 (aws-dev)"
...
bash-5.1# cat /etc/host-containers/host-containers.toml
# looked as expected!
Looks good to me as well