Implement a lightweight cloud-init system for first-boot configuration: - Go parser for YAML config (hostname, network, KubeSolo settings) - Static/DHCP network modes with DNS override - KubeSolo extra flags and API server SAN configuration - Portainer Edge Agent and air-gapped deployment support - New init stage 45-cloud-init.sh runs before network/hostname stages - Stages 50/60 skip gracefully when cloud-init has already applied - Build script compiles static Linux/amd64 binary (~2.7 MB) - 17 unit tests covering parsing, validation, and example files - Full documentation at docs/cloud-init.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
1.1 KiB
Bash
Executable File
35 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# 60-hostname.sh — Set system hostname
|
|
# If cloud-init (stage 45) already set the hostname, skip this stage.
|
|
|
|
# Cloud-init writes /etc/hostname and saves to data partition
|
|
if [ "$CLOUDINIT_APPLIED" = "1" ] && [ -f /etc/hostname ]; then
|
|
HOSTNAME="$(cat /etc/hostname)"
|
|
if [ -n "$HOSTNAME" ]; then
|
|
log "Hostname already set by cloud-init: $HOSTNAME"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
if [ -f "$DATA_MOUNT/etc-kubesolo/hostname" ]; then
|
|
HOSTNAME="$(cat "$DATA_MOUNT/etc-kubesolo/hostname")"
|
|
elif [ -f /etc/kubesolo/hostname ]; then
|
|
HOSTNAME="$(cat /etc/kubesolo/hostname)"
|
|
else
|
|
# Generate hostname from MAC address of primary interface
|
|
MAC_SUFFIX=""
|
|
for iface in /sys/class/net/*; do
|
|
iface="$(basename "$iface")"
|
|
case "$iface" in lo|docker*|veth*|br*|cni*) continue ;; esac
|
|
MAC_SUFFIX="$(cat "/sys/class/net/$iface/address" 2>/dev/null | tr -d ':' | tail -c 7)"
|
|
break
|
|
done
|
|
HOSTNAME="kubesolo-${MAC_SUFFIX:-unknown}"
|
|
fi
|
|
|
|
hostname "$HOSTNAME"
|
|
echo "$HOSTNAME" > /etc/hostname
|
|
echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
|
|
|
|
log_ok "Hostname set to: $HOSTNAME"
|