Files
homelab/scripts/import-cluster-access.sh
T
k.rennerandClaude Opus 4.7 2437b7d733 fix: Auto-fetch latest access files in import script
The rebuild pipeline commits a new talosconfig/kubeconfig each run.
Without a git pull beforehand, import-cluster-access imports stale
configs and kubectl fails with x509 CA mismatch against the newly
rebuilt cluster.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 21:44:50 +02:00

30 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Import SOPS-encrypted talosconfig and kubeconfig from the rebuild pipeline
# into local ~/.talos/config and ~/.kube/config.
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ACCESS_DIR="$REPO_ROOT/kubernetes/access"
# Pull latest access files — the rebuild pipeline commits new talos/kube configs each run
echo "Fetching latest access files from origin..."
git -C "$REPO_ROOT" fetch --quiet origin master
git -C "$REPO_ROOT" checkout --quiet origin/master -- kubernetes/access/ 2>/dev/null || true
[[ -f "$ACCESS_DIR/talosconfig.sops" ]] || { echo "talosconfig.sops not found — run the rebuild-k8s pipeline first"; exit 1; }
[[ -f "$ACCESS_DIR/kubeconfig.sops" ]] || { echo "kubeconfig.sops not found — run the rebuild-k8s pipeline first"; exit 1; }
mkdir -p ~/.talos ~/.kube
sops -d --input-type binary --output-type binary "$ACCESS_DIR/talosconfig.sops" > ~/.talos/config
chmod 600 ~/.talos/config
sops -d --input-type binary --output-type binary "$ACCESS_DIR/kubeconfig.sops" > ~/.kube/config
chmod 600 ~/.kube/config
echo "Imported:"
echo " ~/.talos/config"
echo " ~/.kube/config"
kubectl get nodes 2>&1 | head -5