Skip to content

Commit 3c7a5bc

Browse files
committed
feat(installer): auto-install kubectl as required dependency
1 parent 795324f commit 3c7a5bc

2 files changed

Lines changed: 66 additions & 8 deletions

File tree

install.sh

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
VERSION="1.1.1"
4+
VERSION="1.1.2"
55
REPO="zjy365/seakills"
66
SITE_URL="https://seakills.gzg.sealos.run"
77

@@ -75,6 +75,61 @@ else
7575
fi
7676
echo ""
7777

78+
# --- Install kubectl if missing ---
79+
AGENTS_BIN="$HOME/.agents/bin"
80+
81+
install_kubectl() {
82+
if command -v kubectl &>/dev/null; then
83+
echo "kubectl: $(kubectl version --client --short 2>/dev/null || kubectl version --client 2>/dev/null | head -1) (already installed)"
84+
return 0
85+
fi
86+
87+
echo "Installing kubectl..."
88+
89+
local os arch
90+
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
91+
arch="$(uname -m)"
92+
case "$arch" in
93+
x86_64|amd64) arch="amd64" ;;
94+
aarch64|arm64) arch="arm64" ;;
95+
*) echo " ✗ Unsupported architecture: $arch"; return 1 ;;
96+
esac
97+
98+
# Get latest stable version
99+
local kube_version
100+
kube_version="$(curl -fsSL --connect-timeout 10 https://dl.k8s.io/release/stable.txt 2>/dev/null)" || kube_version="v1.32.0"
101+
102+
mkdir -p "$AGENTS_BIN"
103+
local url="https://dl.k8s.io/release/${kube_version}/bin/${os}/${arch}/kubectl"
104+
105+
if curl -fsSL --connect-timeout 15 "$url" -o "$AGENTS_BIN/kubectl" 2>/dev/null; then
106+
chmod +x "$AGENTS_BIN/kubectl"
107+
echo " ✓ kubectl ${kube_version}$AGENTS_BIN/kubectl"
108+
else
109+
echo " ✗ kubectl download failed (deploy will still work, but updates require full re-deploy)"
110+
return 1
111+
fi
112+
113+
# Silently add ~/.agents/bin to PATH in shell profiles (idempotent)
114+
local path_line="export PATH=\"\$HOME/.agents/bin:\$PATH\""
115+
local fish_line="fish_add_path -g \$HOME/.agents/bin"
116+
117+
for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
118+
if [ -f "$rc" ]; then
119+
grep -qF '.agents/bin' "$rc" 2>/dev/null || echo "$path_line" >> "$rc"
120+
fi
121+
done
122+
123+
# Fish config
124+
local fish_conf="$HOME/.config/fish/config.fish"
125+
if [ -f "$fish_conf" ]; then
126+
grep -qF '.agents/bin' "$fish_conf" 2>/dev/null || echo "$fish_line" >> "$fish_conf"
127+
fi
128+
}
129+
130+
install_kubectl || true
131+
echo ""
132+
78133
# --- Download skills ---
79134
tmp="$(mktemp -d)"
80135
trap 'rm -rf "$tmp"' EXIT

skills/sealos-deploy/modules/preflight.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ git --version 2>/dev/null
2727
node --version 2>/dev/null
2828
python3 --version 2>/dev/null
2929

30-
# Optional (enables in-place updates of deployed apps)
31-
kubectl version --client 2>/dev/null
30+
# Required (enables in-place updates of deployed apps)
31+
# Check PATH first, then fallback to ~/.agents/bin/
32+
kubectl version --client 2>/dev/null || ~/.agents/bin/kubectl version --client 2>/dev/null
3233

3334
# Always available (system built-in)
3435
curl --version 2>/dev/null | head -1
@@ -57,7 +58,7 @@ ENV.docker = true/false
5758
ENV.git = true/false
5859
ENV.node = true/false (18+ required)
5960
ENV.python = true/false
60-
ENV.kubectl = true/false
61+
ENV.kubectl = true/false (if false, check ~/.agents/bin/kubectl)
6162
ENV.curl = true/false
6263
ENV.jq = true/false
6364
```
@@ -90,9 +91,11 @@ docker info 2>/dev/null
9091
**Python:**
9192
- If missing, Sealos template validation (Phase 5) uses AI self-check instead of `quality_gate.py`
9293

93-
**kubectl:**
94-
- If available, enables in-place update of already-deployed apps (`kubectl set image`, `kubectl rollout`)
95-
- If missing, updates require a full re-deploy through the Template API
94+
**kubectl (required):**
95+
- Installed automatically by `install.sh` to `~/.agents/bin/kubectl`
96+
- If `kubectl` is not in PATH, use `~/.agents/bin/kubectl` as the absolute path for all kubectl commands
97+
- Enables in-place update of already-deployed apps (`kubectl set image`, `kubectl rollout`)
98+
- If somehow missing, guide user to re-run the installer: `curl -fsSL https://seakills.gzg.sealos.run/install.sh | bash`
9699

97100
## Step 2: Project Context
98101

@@ -420,7 +423,7 @@ Environment: (cached / refreshed)
420423
✓ git <version>
421424
○ Node.js <version> (or: ✗ Node.js — using AI fallback mode)
422425
○ Python <version> (or: ✗ Python — template validation via AI)
423-
kubectl <version> (or: ✗ kubectl — update via re-deploy only)
426+
kubectl <version>
424427
425428
Auth:
426429
✓ Sealos Cloud (<region>)

0 commit comments

Comments
 (0)