node(titan-22): migrate k3s to USB ethernet

This commit is contained in:
jenkins 2026-08-22 20:42:51 -03:00
parent db0cb86ca6
commit 074f988731

View File

@ -58,29 +58,77 @@ spec:
set -u
while true; do
nsenter -t 1 -m -u -i -n -p -- /bin/sh -lc '
usb_if="enx4cea41672a87"
usb_mac="4c:ea:41:67:2a:87"
old_if="enp5s0"
canonical_ip="192.168.22.22"
gateway="192.168.22.1"
k3s_env="/etc/default/k3s-agent"
date -Is
ip link set enp5s0 up || true
ethtool --set-eee enp5s0 eee off || true
ethtool -s enp5s0 advertise 0x020 autoneg on || true
sleep 3
stable=true
for _ in 1 2 3 4 5; do
if ! ethtool enp5s0 | grep -q "Link detected: yes"; then
stable=false
fi
sleep 2
done
if [ "${stable}" != "true" ]; then
echo "link not stable at 1G-only; falling back to 100M-only autoneg"
ethtool -s enp5s0 advertise 0x008 autoneg on || true
sleep 5
if [ ! -d "/sys/class/net/${usb_if}" ]; then
echo "USB Ethernet interface ${usb_if} is missing"
exit 0
fi
ethtool --show-eee enp5s0 || true
ethtool enp5s0 | sed -n "1,45p" || true
ip -br addr show enp5s0 || true
detected_mac="$(cat "/sys/class/net/${usb_if}/address")"
if [ "${detected_mac}" != "${usb_mac}" ]; then
echo "refusing to configure ${usb_if}: unexpected MAC ${detected_mac}"
exit 0
fi
if nmcli connection show "Wired connection 1" >/dev/null 2>&1; then
nmcli connection modify "Wired connection 1" connection.autoconnect no || true
fi
nmcli device disconnect "${old_if}" >/dev/null 2>&1 || true
ip link set "${old_if}" down || true
connection="$(nmcli -g GENERAL.CONNECTION device show "${usb_if}" 2>/dev/null || true)"
if [ -z "${connection}" ] || [ "${connection}" = "--" ]; then
connection="titan-22-usb-primary"
if ! nmcli connection show "${connection}" >/dev/null 2>&1; then
nmcli connection add type ethernet ifname "${usb_if}" con-name "${connection}"
fi
fi
nmcli connection modify "${connection}" \
connection.interface-name "${usb_if}" \
connection.autoconnect yes \
connection.autoconnect-priority 100 \
ipv4.method manual \
ipv4.addresses "${canonical_ip}/24" \
ipv4.gateway "${gateway}" \
ipv4.dns "${gateway}" \
ipv4.dns-search titan \
ipv6.method auto
if ! ip -4 address show dev "${usb_if}" | grep -q " ${canonical_ip}/24"; then
echo "moving the canonical node address to ${usb_if}"
nmcli connection up "${connection}" ifname "${usb_if}"
fi
ip link set "${usb_if}" up
ethtool --set-eee "${usb_if}" eee off || true
mkdir -p "$(dirname "${k3s_env}")"
env_tmp="$(mktemp)"
if [ -f "${k3s_env}" ]; then
grep -v -E "^K3S_(NODE_IP|FLANNEL_IFACE)=" "${k3s_env}" >"${env_tmp}" || true
fi
printf "K3S_NODE_IP=%s\\nK3S_FLANNEL_IFACE=%s\\n" \
"${canonical_ip}" "${usb_if}" >>"${env_tmp}"
if ! cmp -s "${env_tmp}" "${k3s_env}"; then
install -m 0644 "${env_tmp}" "${k3s_env}"
echo "updated k3s network environment"
fi
rm -f "${env_tmp}"
# k3s embeds kubelet; the standalone Debian unit only crash-loops.
systemctl disable --now kubelet.service >/dev/null 2>&1 || true
ethtool "${usb_if}" | sed -n "1,45p" || true
ip -br address show "${usb_if}" || true
ip -d link show flannel.1 | sed -n "1,3p" || true
'
sleep 30
sleep 60
done