Refactor ignition support during dracut

- Control root device using the node/profile root field
- Add support for `/warewulf/wwinit.d` to run scripts during first stage
- Move first-stage ignition support to `/warewulf/wwinit.d/`
- Add `wwctl <node|profile> set --parttype`
- Add overlay template functions `SystemdEscape` and `SystemdEscapePath`
- Support configuring ignition with resources

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-06-30 23:09:49 -06:00
parent 608ef89d40
commit b98eae4b01
29 changed files with 787 additions and 354 deletions

View File

@@ -1,52 +1,15 @@
#!/bin/bash
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"
}
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
get_stage() {
stage="${1}"
info "warewulf: loading stage: ${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}" \
@@ -55,19 +18,29 @@ for stage in $archives ; do
--data-urlencode "compress=gz" \
"${wwinit_uri}" \
| gzip -d \
| cpio -im --directory="${NEWROOT}"
| cpio -ium --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"
mkdir /tmp/wwinit
(
# fetch the system overlay into /tmp/wwinit
local NEWROOT=/tmp/wwinit
get_stage "system"
)
if [ -x /tmp/wwinit/warewulf/run-wwinit.d ]; then
PREFIX=/tmp/wwinit /tmp/wwinit/warewulf/run-wwinit.d
fi
info "warewulf: Finished warewulf v4 dracut"
info "warewulf: mounting ${wwinit_root_device} at ${NEWROOT}"
(
if [ "${wwinit_root_device}" = "tmpfs" ]; then
mount -t tmpfs -o mpol=interleave ${wwinit_tmpfs_size_option} "${wwinit_root_device}" "${NEWROOT}"
else
mount "${wwinit_root_device}" "${NEWROOT}"
fi
) || die "warewulf: failed to mount ${wwinit_root_device} at ${NEWROOT}"
for stage in "image" "system" "runtime"; do
get_stage "${stage}"
done