Files
kubesolo-os/build/rootfs/usr/lib/kubesolo-os/network.sh
Adolfo Delorenzo e372df578b feat: initial Phase 1 PoC scaffolding for KubeSolo OS
Complete Phase 1 implementation of KubeSolo OS — an immutable, bootable
Linux distribution built on Tiny Core Linux for running KubeSolo
single-node Kubernetes.

Build system:
- Makefile with fetch, rootfs, initramfs, iso, disk-image targets
- Dockerfile.builder for reproducible builds
- Scripts to download Tiny Core, extract rootfs, inject KubeSolo,
  pack initramfs, and create bootable ISO/disk images

Init system (10 POSIX sh stages):
- Early mount (proc/sys/dev/cgroup2), cmdline parsing, persistent
  mount with bind-mounts, kernel module loading, sysctl, DHCP
  networking, hostname, clock sync, containerd prep, KubeSolo exec

Shared libraries:
- functions.sh (device wait, IP lookup, config helpers)
- network.sh (static IP, config persistence, interface detection)
- health.sh (containerd, API server, node readiness checks)
- Emergency shell for boot failure debugging

Testing:
- QEMU boot test with serial log marker detection
- K8s readiness test with kubectl verification
- Persistence test (reboot + verify state survives)
- Workload deployment test (nginx pod)
- Local storage test (PVC + local-path provisioner)
- Network policy test
- Reusable run-vm.sh launcher

Developer tools:
- dev-vm.sh (interactive QEMU with port forwarding)
- rebuild-initramfs.sh (fast iteration)
- inject-ssh.sh (dropbear SSH for debugging)
- extract-kernel-config.sh + kernel-audit.sh

Documentation:
- Full design document with architecture research
- Boot flow documentation covering all 10 init stages
- Cloud-init examples (DHCP, static IP, Portainer Edge, air-gapped)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 10:18:42 -06:00

81 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# network.sh — Network configuration helpers for KubeSolo OS init
# Sourced by init stages. POSIX sh only.
# Configure a static IP address on an interface
# Usage: static_ip <iface> <ip/prefix> <gateway> [dns1] [dns2]
static_ip() {
iface="$1" addr="$2" gw="$3" dns1="${4:-}" dns2="${5:-}"
ip link set "$iface" up
ip addr add "$addr" dev "$iface"
ip route add default via "$gw" dev "$iface"
# Write resolv.conf
: > /etc/resolv.conf
[ -n "$dns1" ] && echo "nameserver $dns1" >> /etc/resolv.conf
[ -n "$dns2" ] && echo "nameserver $dns2" >> /etc/resolv.conf
}
# Save current network configuration for persistence across reboots
# Writes a shell script that can be sourced to restore networking
save_network_config() {
dest="${1:-/mnt/data/network/interfaces.sh}"
mkdir -p "$(dirname "$dest")"
iface=""
for d in /sys/class/net/*; do
name="$(basename "$d")"
case "$name" in lo|docker*|veth*|br*|cni*) continue ;; esac
iface="$name"
break
done
[ -z "$iface" ] && return 1
addr=$(ip -4 addr show "$iface" | sed -n 's/.*inet \([0-9./]*\).*/\1/p' | head -1)
gw=$(ip route show default 2>/dev/null | sed -n 's/default via \([0-9.]*\).*/\1/p' | head -1)
cat > "$dest" << SCRIPT
#!/bin/sh
# Auto-saved network config — generated by KubeSolo OS
ip link set $iface up
ip addr add $addr dev $iface
ip route add default via $gw dev $iface
SCRIPT
# Append DNS if resolv.conf has entries
if [ -f /etc/resolv.conf ]; then
echo ": > /etc/resolv.conf" >> "$dest"
sed -n 's/^nameserver \(.*\)/echo "nameserver \1" >> \/etc\/resolv.conf/p' \
/etc/resolv.conf >> "$dest"
fi
chmod +x "$dest"
}
# Get the primary network interface name
get_primary_iface() {
for d in /sys/class/net/*; do
name="$(basename "$d")"
case "$name" in lo|docker*|veth*|br*|cni*) continue ;; esac
echo "$name"
return 0
done
return 1
}
# Wait for link on an interface
wait_for_link() {
iface="$1"
timeout="${2:-15}"
i=0
while [ "$i" -lt "$timeout" ]; do
if ip link show "$iface" 2>/dev/null | grep -q 'state UP'; then
return 0
fi
sleep 1
i=$((i + 1))
done
return 1
}