Skip to content

Commit ecfd83b

Browse files
committed
fix(helm-e2e): read default gateway from /proc/net/route, not iproute2
The CI container (ghcr.io/nvidia/openshell/ci:latest) does not have the `ip` command installed, so the kubeconfig-rewrite block exited 127 with `set -euo pipefail`. Read the default gateway directly from /proc/net/route instead — that file is always present on Linux and needs no extra package. Decode the gateway field as a little-endian 32-bit hex string into dotted decimal.
1 parent d138767 commit ecfd83b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

tasks/scripts/helm-k3s-local.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,19 @@ merge_kubeconfig() {
129129
old_server=$(kubectl --kubeconfig="${KUBECONFIG_TARGET}" config view --raw \
130130
-o "jsonpath={.clusters[?(@.name=='${context}')].cluster.server}")
131131
if [[ "${old_server}" == https://0.0.0.0:* ]]; then
132-
host_addr=$(ip route show default 2>/dev/null | awk '/default/ {print $3; exit}')
132+
# Read the default-route gateway from /proc/net/route directly to avoid
133+
# depending on the `ip` command, which is not in the CI image. The
134+
# gateway field is a little-endian 32-bit hex value, so we read pairs
135+
# of hex digits in reverse and format as dotted decimal.
136+
host_addr=$(awk '$2=="00000000" {
137+
gw = $3
138+
printf "%d.%d.%d.%d",
139+
strtonum("0x" substr(gw,7,2)),
140+
strtonum("0x" substr(gw,5,2)),
141+
strtonum("0x" substr(gw,3,2)),
142+
strtonum("0x" substr(gw,1,2))
143+
exit
144+
}' /proc/net/route 2>/dev/null) || host_addr=""
133145
if [[ -n "${host_addr}" ]]; then
134146
new_server="${old_server//0.0.0.0/${host_addr}}"
135147
echo "Inside container; rewriting kubeconfig server ${old_server} -> ${new_server} (insecure-skip-tls-verify)."

0 commit comments

Comments
 (0)