#!/bin/bash
set -euo pipefail

# Install K3s. Bound both network and installer time so an unreachable
# download source cannot hold the MCP request indefinitely.
curl -sfL --connect-timeout 10 --max-time 60 https://get.k3s.io | sh -

# Wait for k3s to be ready
echo "Waiting for k3s to start..."
if ! timeout 180s bash -c 'until kubectl get nodes &>/dev/null; do sleep 2; done'; then
    echo "Timed out waiting for k3s to become ready" >&2
    exit 1
fi

echo "K3s installed successfully"
kubectl get nodes
