add support for ignition in configs

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2024-11-08 15:59:10 +01:00
committed by Jonathon Anderson
parent b8641b8569
commit 917f191abe
6 changed files with 92 additions and 42 deletions

70
dracut/modules.d/90wwinit/load-wwinit.sh Executable file → Normal file
View File

@@ -1,19 +1,52 @@
#!/bin/bash
info "Mounting tmpfs at $NEWROOT"
mount -t tmpfs -o mpol=interleave ${wwinit_tmpfs_size_option} tmpfs "$NEWROOT"
function setup_disks() {
# format and prepare the disk(s)
/usr/bin/ignition --root=/sysroot --platform=metal --stage=disks || die "warewulf: failed to partition/format disk"
# mount /dev/disk/by-partlabel/root "$NEWROOT" || die "warewulf: failed to mount new root"
/usr/bin/ignition --root=/sysroot --platform=metal --stage=mount || die "warewulf: failed to mount disk"
for stage in "image" "system" "runtime"
do
info "Loading stage: ${stage}"
# Load runtime overlay from a static privledged port.
# Others use default settings.
localport=""
if [[ "${stage}" == "runtime" ]]
then
}
info "warewulf: Running warewulf v4 dracut init ${wwinit_persistent}"
archives="image system runtime"
if [ ${wwinit_persistent} -ne 1 ] ; then
info "warewulf: Mounting tmpfs at $NEWROOT"
mount -t tmpfs -o mpol=interleave ${wwinit_tmpfs_size_option} tmpfs "$NEWROOT"
else
info "warewulf: Using persistent setup ${wwinit_ignition}/ignition.json.ww?render=${wwinit_id}"
# get the igintion config and store in /run/igintion.ign, don't use igntion as so we can
# construct the download link
curl --location --silent --get ${localport} \
--retry 60 --retry-delay 1 \
"${wwinit_ignition}/ignition.json.ww?render=${wwinit_id}" -o /run/ignition-rootfs.json || die "warewulf: failed to fetch ignition configuration from ${wwinit_ignition}/ignition.json.ww?render=${wwinit_id}"
jq '.storage.filesystems |= map(select(.device=="/dev/disk/by-partlabel/rootfs").path="/")' /run/ignition-rootfs.json > /run/ignition.json || die "warewulf: failed to rewrite ignition configuration"
setup_disks
# if [ -e ${NEWROOT}/warewulf/ww_${wwinit_imagename} ] ; then
# info "warewulf: found ${NEWROOT}/warewulf/ww_${wwinit_imagename} running rsync for update"
# # we need only the overlays as we update the root
# # with rsync when the same image is used
# archives="system runtime"
# rsync -aux --delete --exclude=/proc/ --exclude=/sys/ --exclude=/dev rsync://${wwinit_ip}/${wwinit_imagename} $NEWROOT || die "warewulf: failed to run rsync"
# elif [ -e ${NEWROOT}/warewulf/ww_* ] ; then
# info "warewulf: found $(ls ${NEWROOT}/warewulf/ww_*) but image is ${wwinit_imagename}, wiping $NEWROOT"
# # we didn't have the wanted image but provisioned with warewulf, wipe the rootfs
# /usr/bin/ignition --root=/sysroot --platform=metal --stage=umount || die "warewulf: failed to mount disk"
# jq '.storage.filesystems |= map(select(.device=="/dev/disk/by-partlabel/rootfs").wipeFilesystem=true)' /run/ignition.json > /run/ignition.json.mod || die "couldn't reformation ignition configuration"
# mv /run/ignition.json.mod /run/ignition.json || die "warewulf: couldn't mv ignition configuration back"
# setup_disks
# fi
fi
for stage in $archives ; do
info "warewulf: Loading ${stage}"
# Load runtime overlay from a static privledged port.
# Others use default settings.
localport=""
if [[ "${stage}" == "runtime" ]] ; then
localport="--local-port 1-1023"
fi
(
fi
(
curl --location --silent --get ${localport} \
--retry 60 --retry-connrefused --retry-delay 1 \
--data-urlencode "assetkey=${wwinit_assetkey}" \
@@ -25,3 +58,16 @@ do
| cpio -im --directory="${NEWROOT}"
) || die "Unable to load stage: ${stage}"
done
if [ ${wwinit_persistent} -eq 1 ] ; then
# this avoids that ignition runs a second time
info "warewulf: removing ignition config from wwinit image"
rm -rf ${NEWROOT}/warewulf/ignition.json
echo "Container name of persistent install: ${wwinit_imagename}" > ${NEWROOT}/warewulf/ww_${wwinit_imagename}
echo "# created from ${wwinit_ignition_uri}/fstab.ww?render=${winit_id}" > ${NEWROOT}/etc/fstab
curl --location --silent --get ${localport} \
--retry 60 --retry-delay 1 \
"${wwinit_ignition}/fstab.ww?render=${wwinit_id}" >> ${NEWROOT}/etc/fstab || die "warewulf: failed to write correct fstab"
fi
info "warewulf: Finished warewulf v4 dracut"

4
dracut/modules.d/90wwinit/module-setup.sh Executable file → Normal file
View File

@@ -9,12 +9,12 @@ check() {
}
depends() {
echo network
echo network ignition
return 0
}
install() {
inst_multiple cpio curl dmidecode
inst_multiple cpio curl dmidecode rsync jq
inst_hook cmdline 30 "$moddir/parse-wwinit.sh"
inst_hook pre-mount 30 "$moddir/load-wwinit.sh"
if dracut_module_included "network-manager" && dracut_module_included "systemd"

26
dracut/modules.d/90wwinit/parse-wwinit.sh Executable file → Normal file
View File

@@ -3,25 +3,27 @@
[ -z "$root" ] && root=$(getarg root=)
if [ "${root}" = "wwinit" ]
then
info "root=${root}"
if [ "${root}" = "wwinit" ] || [ "${root}" = "persistent" ] ; then
info "warewulf: root=${root}"
export wwinit_uuid=$(dmidecode -s system-uuid)
export wwinit_assetkey=$(dmidecode -s chassis-asset-tag)
export wwinit_uri="$(getarg wwinit.uri)"
export wwinit_ignition="$(getarg wwinit.ignition)"
export wwinit_ip="$(getarg wwinit.ip)"
export wwinit_imagename="$(getarg wwinit.imagename)"
export wwinit_id=$(getarg wwinit.id)
wwinit_tmpfs_size=$(getarg wwinit.tmpfs.size=)
if [ -n "$wwinit_tmpfs_size" ]
then
info "wwinit.tmpfs.size=${wwinit_tmpfs_size}"
if [ -n "$wwinit_tmpfs_size" ] ; then
info "warewulf: wwinit.tmpfs.size=${wwinit_tmpfs_size}"
export wwinit_tmpfs_size_option="-o size=${wwinit_tmpfs_size}"
fi
if [ -n "${wwinit_uri}" ]
then
info "Found root=${root} and a Warewulf server uri. Will boot from Warewulf."
if [ "${root}" = "persistent" ] ; then
export wwinit_persistent="1"; info "warewulf: wwinit_persistent=$wwinit_persistent"
fi
if [ -n "${wwinit_uri}" ] ; then
info "warewulf: Found root=${root} and a Warewulf server uri. Will boot from Warewulf."
rootok=1
else
die "Found root=${root} but no Warewulf server uri. Cannot boot from Warewulf."
die "warewulf: Found root=${root} but no Warewulf server uri. Cannot boot from Warewulf."
fi
fi