fix(k8s): setup-k8s.sh — fail phase 3 on build errors, fix non-root crash

- Phase 3 now exits with error if any image builds fail, preventing
  mark_phase_done from running. Previously it just warned and continued,
  which could lead to phase 5 deploying with missing images.
- Moved mkdir from top-level scope into mark_phase_done(). The old
  top-level mkdir -p /opt/bytelyst/.setup-state-k8s crashed non-root
  invocations (--status, --help) due to set -e + permission denied.
- Fixed header comment: 'containerd' → 'Docker runtime' (we use --docker).
- Added --resume to header usage block (was supported but undocumented).
This commit is contained in:
saravanakumardb1 2026-03-24 14:52:53 -07:00
parent a25d6f7847
commit 32522b218a

View File

@ -11,13 +11,14 @@
# What this script does:
# Phase 1: Pre-flight checks (verify docker phases ran)
# Phase 2: Install k3s (lightweight K8s)
# Phase 3: Build Docker images + import into k3s containerd
# Phase 3: Build Docker images (reused by k3s via --docker runtime)
# Phase 4: Generate K8s secrets (JWT, etc.)
# Phase 5: Apply K8s manifests (namespaces → config → infra → platform → products)
# Phase 6: Health check
#
# Usage:
# sudo ./setup-k8s.sh # Full install
# sudo ./setup-k8s.sh --resume # Auto-resume from last completed phase
# sudo ./setup-k8s.sh --phase=N # Run single phase (1-6)
# sudo ./setup-k8s.sh --status # Show phase status
# sudo ./setup-k8s.sh --reset # Clear markers, start fresh
@ -58,10 +59,9 @@ ok() { echo -e "${GREEN} ✓ $*${NC}"; }
warn() { echo -e "${YELLOW}$*${NC}"; }
fail() { echo -e "${RED}$*${NC}" >&2; exit 1; }
mkdir -p "$STATE_DIR"
mark_phase_done() { date -Iseconds > "${STATE_DIR}/phase${1}.done"; }
mark_phase_done() { mkdir -p "$STATE_DIR"; date -Iseconds > "${STATE_DIR}/phase${1}.done"; }
is_phase_done() { [ -f "${STATE_DIR}/phase${1}.done" ]; }
reset_markers() { rm -f "${STATE_DIR}"/phase*.done; log "Phase markers cleared."; }
reset_markers() { rm -f "${STATE_DIR}"/phase*.done 2>/dev/null; log "Phase markers cleared."; }
last_completed_phase() {
local last=0
@ -233,6 +233,10 @@ phase3_images() {
log " Built: ${build_ok}, Failed: ${build_fail}"
[ "$build_fail" -eq 0 ] || warn " ${build_fail} images failed to build. Fix and re-run: sudo ./setup-k8s.sh --phase=3"
if [ "$build_fail" -gt 0 ]; then
fail "Phase 3 incomplete: ${build_fail}/${total} images failed. Fix and re-run: sudo ./setup-k8s.sh --phase=3"
fi
ok "Phase 3 complete. ${build_ok}/${total} images ready."
}