2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-10-20 06:35:33 +00:00

Draft media based images

Prepare for media based diskless images
This commit is contained in:
Jarrod Johnson
2026-08-26 16:13:34 -04:00
parent bbad91369f
commit 1da744fcab
3 changed files with 93 additions and 13 deletions
@@ -103,13 +103,38 @@ cd - > /dev/null
mkdir -p /etc/ssl/certs
cat /tls/*.pem > /etc/ssl/certs/ca-certificates.crt
cat /tls/*.pem > /etc/confluent/ca.pem
/opt/confluent/bin/copernicus -t > /etc/confluent/confluent.info
if [ -e /dev/disk/by-label/CNFLNT_MBI ]; then # media based image
mbimntpoint=$(mktemp -d)
mount /dev/disk/by-label/CNFLNT_MBI $mbimntpoint
echo EXTMGRINFO: media||1 > /etc/confluent/confluent.info
else
/opt/confluent/bin/copernicus -t > /etc/confluent/confluent.info
fi
TRIES=0
while ! grep ^EXTMGRINFO: /etc/confluent/confluent.info | awk -F'|' '{print $3}' | grep 1 > /dev/null && [ "$TRIES" -lt 30 ]; do
TRIES=$((TRIES + 1))
if [ -e /dev/disk/by-label/CNFLNT_MBI ]; then
mbimntpoint=$(mktemp -d)
mount /dev/disk/by-label/CNFLNT_MBI $mbimntpoint
echo EXTMGRINFO: media||1 > /etc/confluent/confluent.info
break
fi
/opt/confluent/bin/copernicus -t > /etc/confluent/confluent.info
sleep 1
done
if [ -n "$mbimntpoint" ]; then
sed -i '/^EXTMGRINFO:/d' /etc/confluent/confluent.info
if [ -e $mbimntpoint/confluent/confluent.info ]; then
cp $mbimntpoint/confluent/confluent.info /etc/confluent/
fi
if [ -e $mbimntpoint/confluent/confluent.deploycfg ]; then
cp $mbimntpoint/confluent/confluent.deploycfg /etc/confluent/
fi
if [ -e $mbimntpoint/confluent/confluent.apikey ]; then
cp $mbimntpoint/confluent/confluent.apikey /etc/confluent/
fi
fi
confluent_mgr=$(grep '^EXTMGRINFO:.*1$' /etc/confluent/confluent.info | head -n 1 | awk -F': ' '{print $2}' | awk -F'|' '{print $1}')
if [ -z "$confluent_mgr" ]; then
confluent_mgr=$(grep ^MANAGER: /etc/confluent/confluent.info|head -n 1 | awk '{print $2}')
@@ -120,7 +145,15 @@ else
confluent_http_mgr=$confluent_mgr
fi
confluent_nodename=$(grep ^NODENAME: /etc/confluent/confluent.info |awk '{print $NF}')
if [ -z "$confluent_nodename" ]; then
confluent_nodename=standalone
fi
hostname $confluent_nodename
if [ -z "$confluent_mgr" ] && [ -n "$mbimntpoint" ]; then
# Standalone diskless image
cp $mbimntpoint/confluent/scripts/functions /etc/confluent/
exec /bin/bash $mbimntpoint/confluent/scripts/imageboot.sh $mbimntpoint
fi
get_tpm_apikey
if [ -z "$confluent_apikey" ]; then
get_remote_apikey
@@ -1,18 +1,28 @@
confluent_urls=""
confluent_proto=https
for addr in $(grep ^MANAGER: /etc/confluent/confluent.info|awk '{print $2}'|sed -e s/%/%25/); do
if [[ $addr == *:* ]]; then
confluent_urls="$confluent_urls $confluent_proto://[$addr]/confluent-public/os/$confluent_profile/rootimg.sfs"
else
confluent_urls="$confluent_urls $confluent_proto://$addr/confluent-public/os/$confluent_profile/rootimg.sfs"
if [ -n "$1" ] && [ -d "$1" ]; then
mbimntpoint=$1
if [ -e "$mbimntpoint/confluent/rootimg.sfs" ]; then
rootimg="$mbimntpoint/confluent/rootimg.sfs"
fi
done
fi
if [ -z "$rootimg" ]; then
for addr in $(grep ^MANAGER: /etc/confluent/confluent.info|awk '{print $2}'|sed -e s/%/%25/); do
if [[ $addr == *:* ]]; then
confluent_urls="$confluent_urls $confluent_proto://[$addr]/confluent-public/os/$confluent_profile/rootimg.sfs"
else
confluent_urls="$confluent_urls $confluent_proto://$addr/confluent-public/os/$confluent_profile/rootimg.sfs"
fi
done
fi
mkdir -p /mnt/remoteimg /mnt/remote /mnt/overlay
TETHERED=1
if grep -q confluent_imagemethod=untethered /proc/cmdline || grep -q confluent_imagemethod=uncompressed /proc/cmdline; then
TETHERED=0
mount -t tmpfs untethered /mnt/remoteimg
curl https://$confluent_mgr/confluent-public/os/$confluent_profile/rootimg.sfs -o /mnt/remoteimg/rootimg.sfs
elif [ -n "$rootimg" ]; then
ln -s "$rootimg" /mnt/remoteimg/rootimg.sfs
else
confluent_urls="$confluent_urls https://$confluent_mgr/confluent-public/os/$confluent_profile/rootimg.sfs"
/opt/confluent/bin/urlmount $confluent_urls /mnt/remoteimg
@@ -135,12 +145,27 @@ chmod 600 /sysroot/etc/ssh/*_key
mkdir -p /sysroot/usr/share/ca-certificates/confluent/
cp /tls/*.pem /sysroot/usr/share/ca-certificates/confluent/
chroot /sysroot/ update-ca-certificates
curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.service > /sysroot/etc/systemd/system/onboot.service
if [ -n "$mbimntpoint" ]; then
if [ -e "$mbimntpoint/confluent/scripts/onboot.service" ]; then
cp $mbimntpoint/confluent/scripts/onboot.service /sysroot/etc/systemd/system/onboot.service
fi
else
curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.service > /sysroot/etc/systemd/system/onboot.service
fi
mkdir -p /sysroot/opt/confluent/bin
curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.sh > /sysroot/opt/confluent/bin/onboot.sh
if [ -n "$mbimntpoint" ]; then
touch /sysroot/opt/confluent/bin/onboot.sh
if [ -e $mbimntpoint/confluent/scripts/onboot.sh ]; then
cp $mbimntpoint/confluent/scripts/onboot.sh /sysroot/opt/confluent/bin/onboot.sh
fi
else
curl -sf https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/onboot.sh > /sysroot/opt/confluent/bin/onboot.sh
fi
chmod +x /sysroot/opt/confluent/bin/onboot.sh
cp /opt/confluent/bin/apiclient /sysroot/opt/confluent/bin
ln -s /etc/systemd/system/onboot.service /sysroot/etc/systemd/system/multi-user.target.wants/onboot.service
if [ -e /sysroot/etc/systemd/system/onboot.service ]; then
ln -s /etc/systemd/system/onboot.service /sysroot/etc/systemd/system/multi-user.target.wants/onboot.service
fi
cp /etc/confluent/functions /sysroot/etc/confluent/functions
mv /lib/modules/$(uname -r) /lib/modules/$(uname -r)-ramfs
ln -s /sysroot/lib/modules/$(uname -r) /lib/modules/
@@ -182,9 +207,9 @@ EOF
fi
if [ -n "$ipv4gateway" -a "$ipv4gateway" != "none" -a "$ipv4gateway" != "null" ]; then
cat >> /sysroot/etc/netplan/10-${iface}-confluentcfg.yaml <<EOF
routes:
- to: default
via: $ipv4gateway
routes:
- to: default
via: $ipv4gateway
EOF
fi
fi
@@ -195,4 +220,14 @@ if grep installtodisk /proc/cmdline > /dev/null; then
run_remote installimage
exec reboot -f
fi
if [ -n "$mbimntpoint" ]; then
for archive in $mbimntpoint/confluent/addons/*.t*; do
[ -f "$archive" ] || continue
tar -xpf "$archive" -C /sysroot
done
mkdir -p /sysroot/var/opt/confluent/mbi
mount -o bind $mbimntpoint /sysroot/var/opt/confluent/mbi
mkdir -p /sysroot/etc/confluent
echo /dev/disk/by-label/CNFLNT_MBI > /sysroot/etc/confluent/mbidevice
fi
exec /opt/confluent/bin/start_root
@@ -27,6 +27,18 @@ chmod 600 /var/log/confluent/confluent-onboot.log
tail -f /var/log/confluent/confluent-onboot.log > /dev/console &
logshowpid=$!
if [ -e /etc/confluent/mbidevice ]; then
for script in /var/opt/confluent/mbi/confluent/onboot.d/*; do
[ -x "$script" ] && "$script"
done
fi
if [ -z "$confluent_mgr" ]; then
echo "Confluent manager not defined"
kill $logshowpid
exit 0
fi
run_remote_python syncfileclient
run_remote_python confignet