Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 52 additions & 17 deletions utils/install-minikube-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@ set -e
echo "Current PATH: $PATH"
echo "Operating System: $(uname -a)"

# --- OS / arch detection ---
OS_KERNEL="$(uname -s)"
case "$OS_KERNEL" in
Linux) HOST_OS=linux ;;
Darwin) HOST_OS=darwin ;;
*) echo "ERROR: unsupported OS: $OS_KERNEL" >&2; exit 1 ;;
esac
Comment on lines +13 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this PR successfully adds OS and architecture detection to install-minikube-cluster.sh, the script still calls install-kubectl.sh (on line 38), which unconditionally downloads the Linux AMD64 binary of kubectl:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

On macOS, this results in an unexecutable Linux ELF binary being installed to ~/.local/bin/kubectl, causing any subsequent kubectl commands to fail with an execution format error.

To fully support macOS, utils/install-kubectl.sh also needs to be updated to detect the OS and architecture (similar to how it is done here) and download the correct binary.


case "$(uname -m)" in
x86_64|amd64) HOST_ARCH=amd64 ;;
arm64|aarch64) HOST_ARCH=arm64 ;;
*) echo "ERROR: unsupported arch: $(uname -m)" >&2; exit 1 ;;
esac

# --- Helper Functions ---
# Check if minikube is installed.
# Check if minikube is installed AND is executable on this host (handles the
# common macOS pitfall of finding a Linux ELF binary on PATH).
minikube_exists() {
command -v minikube >/dev/null 2>&1
command -v minikube >/dev/null 2>&1 && minikube version >/dev/null 2>&1
}

# Get the script directory to reference local scripts reliably.
Expand All @@ -23,16 +38,16 @@ echo "Installing kubectl and helm..."
bash "$SCRIPT_DIR/install-kubectl.sh"
bash "$SCRIPT_DIR/install-helm.sh"

# Install minikube if it isnt already installed.
# Install minikube if it isn't already installed (or isn't executable on this host).
if minikube_exists; then
echo "Minikube already installed."
else
echo "Minikube not found. Installing minikube..."
curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
echo "Minikube not found or not executable on this host. Installing minikube for ${HOST_OS}-${HOST_ARCH}..."
curl -fLO "https://github.com/kubernetes/minikube/releases/latest/download/minikube-${HOST_OS}-${HOST_ARCH}"
sudo install "minikube-${HOST_OS}-${HOST_ARCH}" /usr/local/bin/minikube && rm "minikube-${HOST_OS}-${HOST_ARCH}"
fi

# --- Configure BPF (if available) ---
# --- Configure BPF (Linux only) ---
if [ -f /proc/sys/net/core/bpf_jit_harden ]; then
echo "Configuring BPF: Setting net.core.bpf_jit_harden=0"
echo "net.core.bpf_jit_harden=0" | sudo tee -a /etc/sysctl.conf
Expand All @@ -45,13 +60,24 @@ calculate_safe_memory() {
local floor_mb=2048
local host_reserve_mb=2048

local total_kb avail_kb total_mb avail_mb
total_kb=$(awk '/MemTotal:/ {print $2}' /proc/meminfo)
avail_kb=$(awk '/MemAvailable:/ {print $2}' /proc/meminfo)
total_mb=$(( total_kb / 1024 ))
avail_mb=$(( avail_kb > 0 ? avail_kb / 1024 : (total_mb * 60 / 100) ))
local total_mb avail_mb
if [[ "$HOST_OS" == "darwin" ]]; then
# macOS: total via sysctl, treat "available" as ~60% of total (no
# MemAvailable equivalent that maps cleanly to Docker Desktop's VM budget).
local total_bytes
total_bytes=$(sysctl -n hw.memsize 2>/dev/null || echo 0)
total_mb=$(( total_bytes / 1024 / 1024 ))
avail_mb=$(( total_mb * 60 / 100 ))
else
# Linux: read /proc/meminfo.
local total_kb avail_kb
total_kb=$(awk '/MemTotal:/ {print $2}' /proc/meminfo)
avail_kb=$(awk '/MemAvailable:/ {print $2}' /proc/meminfo)
total_mb=$(( total_kb / 1024 ))
avail_mb=$(( avail_kb > 0 ? avail_kb / 1024 : (total_mb * 60 / 100) ))
fi

# cgroup v2 limit if any
# cgroup v2 limit if any (Linux only).
local cg_raw cg_mb=0
if [[ -r /sys/fs/cgroup/memory.max ]]; then
cg_raw=$(cat /sys/fs/cgroup/memory.max)
Expand Down Expand Up @@ -102,8 +128,14 @@ if [ "$GPU_AVAILABLE" = true ]; then
# Configure Docker for GPU support.
echo "Configuring Docker runtime for GPU support..."
if sudo "$NVIDIA_CTK_PATH" runtime configure --runtime=docker; then
echo "Restarting Docker to apply changes..."
sudo systemctl restart docker
# systemctl is Linux-only; on macOS Docker Desktop is restarted by the
# user via the app, not via a service manager.
if [[ "$HOST_OS" == "linux" ]] && command -v systemctl >/dev/null 2>&1; then
echo "Restarting Docker to apply changes..."
sudo systemctl restart docker
else
echo "Skipping 'systemctl restart docker' on ${HOST_OS}; please restart Docker Desktop manually if needed."
fi
echo "Docker runtime configured successfully."
else
echo "Error: Failed to configure Docker runtime using the NVIDIA Container Toolkit."
Expand All @@ -126,8 +158,11 @@ if [ "$GPU_AVAILABLE" = true ]; then
else
# No GPU: Start minikube without GPU support.
echo "Starting minikube without GPU support..."
# Fix potential permission issues.
sudo sysctl fs.protected_regular=0
# Fix potential permission issues (Linux only — fs.protected_regular is a
# Linux sysctl and macOS does not expose it).
if [[ "$HOST_OS" == "linux" ]]; then
sudo sysctl fs.protected_regular=0
fi
minikube start --memory="${MINIKUBE_MEM}" --driver=docker --force
fi

Expand Down
Loading