Files
kubesolo-os/init/lib/50-network.sh
Adolfo Delorenzo d900fa920e feat: add cloud-init Go parser (Phase 2)
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>
2026-02-11 10:39:05 -06:00

62 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# 50-network.sh — Configure networking
# Priority: cloud-init (stage 45) > saved config > DHCP fallback
# If cloud-init already configured networking, skip this stage
if [ "$CLOUDINIT_APPLIED" = "1" ]; then
log "Network already configured by cloud-init — skipping"
return 0
fi
# Check for saved network config (from previous boot or cloud-init)
if [ -f "$DATA_MOUNT/network/interfaces.sh" ]; then
log "Applying saved network configuration"
. "$DATA_MOUNT/network/interfaces.sh"
return 0
fi
# Fallback: DHCP on first non-loopback interface
log "Configuring network via DHCP"
# Bring up loopback
ip link set lo up
ip addr add 127.0.0.1/8 dev lo
# Find first ethernet interface
ETH_DEV=""
for iface in /sys/class/net/*; do
iface="$(basename "$iface")"
case "$iface" in
lo|docker*|veth*|br*|cni*) continue ;;
esac
ETH_DEV="$iface"
break
done
if [ -z "$ETH_DEV" ]; then
log_err "No network interface found"
return 1
fi
log "Using interface: $ETH_DEV"
ip link set "$ETH_DEV" up
# Run DHCP client (BusyBox udhcpc)
if command -v udhcpc >/dev/null 2>&1; then
udhcpc -i "$ETH_DEV" -s /usr/share/udhcpc/default.script \
-t 10 -T 3 -A 5 -b -q 2>/dev/null || {
log_err "DHCP failed on $ETH_DEV"
return 1
}
elif command -v dhcpcd >/dev/null 2>&1; then
dhcpcd "$ETH_DEV" || {
log_err "DHCP failed on $ETH_DEV"
return 1
}
else
log_err "No DHCP client available (need udhcpc or dhcpcd)"
return 1
fi
log_ok "Network configured on $ETH_DEV"