fix: refresh Pimox kubeconfig for apps
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-05 13:39:57 -06:00
parent bcae6c6bbb
commit b09453843a
1 changed files with 63 additions and 0 deletions

View File

@ -6237,6 +6237,68 @@ require_pimox_app_worker_capacity() {
fi
}
ensure_pimox_kubeconfig() {
local kubeconfig="${KUBECONFIG_PATH}"
local control_plane_host="${LAB_CLUSTER_CONTROL_PLANE_LAN_IP:-${LAB_PIMOX_CONTROL_PLANE_IP:-}}"
local control_plane_user="${LAB_CLUSTER_CONTROL_PLANE_USER:-${LAB_PIMOX_CONTROL_PLANE_USER:-jv}}"
local control_plane_key="${LAB_CLUSTER_CONTROL_PLANE_SSH_KEY_PATH:-${LAB_PIMOX_CONTROL_PLANE_SSH_KEY_PATH:-/home/jv/.ssh/id_ed25519}}"
local tmp_file
if [[ -s "${kubeconfig}" ]] &&
kubectl --kubeconfig "${kubeconfig}" get --raw=/readyz >/dev/null 2>&1; then
return 0
fi
if [[ "${LAB_CLUSTER_PROFILE:-debian}" != "pimox" ]]; then
echo "Kubeconfig is missing or API is unreachable: ${kubeconfig}" >&2
echo "Set LAB_CLUSTER_PROFILE=pimox for Pimox pullback, or run ./jeannie rebuild-cluster for the Debian profile." >&2
exit 1
fi
if [[ -z "${control_plane_host}" ]]; then
echo "LAB_CLUSTER_CONTROL_PLANE_LAN_IP is required to rebuild the Pimox kubeconfig." >&2
exit 1
fi
echo "Refreshing Pimox kubeconfig ${kubeconfig} from ${control_plane_user}@${control_plane_host}..."
tmp_file="$(mktemp "${TMPDIR:-/tmp}/homelab-pimox-kubeconfig.XXXXXX")"
trap 'rm -f "${tmp_file}"' RETURN
mkdir -p "$(dirname "${kubeconfig}")"
if ! ssh -i "${control_plane_key}" \
-o BatchMode=yes \
-o ConnectTimeout=10 \
-o IdentitiesOnly=yes \
-o StrictHostKeyChecking=accept-new \
"${control_plane_user}@${control_plane_host}" \
"sudo cat /etc/kubernetes/admin.conf" >"${tmp_file}"; then
echo "Could not read /etc/kubernetes/admin.conf from Pimox control-plane ${control_plane_host}." >&2
exit 1
fi
python3 - "${tmp_file}" "${control_plane_host}" <<'PY'
import re
import sys
from pathlib import Path
path = Path(sys.argv[1])
host = sys.argv[2]
text = path.read_text(encoding="utf-8")
replacement = rf"\1https://{host}:6443"
text, count = re.subn(r"(^\s*server:\s*)https://[^\s]+:6443", replacement, text, count=1, flags=re.MULTILINE)
if count == 0:
raise SystemExit("admin.conf did not contain a Kubernetes API server URL")
path.write_text(text, encoding="utf-8")
PY
install -m 0600 "${tmp_file}" "${kubeconfig}"
if ! kubectl --kubeconfig "${kubeconfig}" get --raw=/readyz >/dev/null 2>&1; then
echo "Refreshed kubeconfig ${kubeconfig}, but the Kubernetes API is still unreachable." >&2
kubectl --kubeconfig "${kubeconfig}" get nodes -o wide >&2 || true
exit 1
fi
}
pimox_primary_worker_inventory() {
local spec_file="${REPO_ROOT}/.lab/pimox-workers.tsv"
local worker_key
@ -6525,6 +6587,7 @@ apps() {
export TF_VAR_kubeconfig_path="${TF_VAR_kubeconfig_path:-${KUBECONFIG_PATH}}"
export KUBECONFIG_PATH="${TF_VAR_kubeconfig_path}"
ensure_pimox_kubeconfig
require_argocd_application_controller
require_pimox_app_worker_capacity
ensure_pimox_registry_storage_path