From f937c2589d4f8c178872c44b95982cc2690547b4 Mon Sep 17 00:00:00 2001 From: alkatrazz Date: Thu, 14 May 2026 17:57:12 +0200 Subject: [PATCH] =?UTF-8?q?fix(funk-cluster):=20grep=20-c=20bug=20+=20unco?= =?UTF-8?q?rdon=20automatique=20au=20d=C3=A9marrage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - check_k8s_pods : grep -c retournait "0\n0" (|| echo 0 inutile quand grep-c affiche 0 même en cas d'absence de match) — utilise un cache intermédiaire pods_output + running=$(grep -c) || running=0 - cmd_start : uncordon automatique si nœuds SchedulingDisabled détectés (séquelle d'un funk-stop --k8s), suivi d'une attente pod infra avant le check — évite de devoir passer --k8s juste pour débloquer le cluster Co-Authored-By: Claude Sonnet 4.6 --- ansible/roles/litellm/files/funk-cluster | 35 +++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/ansible/roles/litellm/files/funk-cluster b/ansible/roles/litellm/files/funk-cluster index 1c2e89f..b77a4af 100644 --- a/ansible/roles/litellm/files/funk-cluster +++ b/ansible/roles/litellm/files/funk-cluster @@ -152,20 +152,20 @@ check_k8s() { check_k8s_pods() { local ns=$1 label=$2 - local total running - total=$($KUBECTL get pods -n "$ns" --no-headers 2>/dev/null | wc -l) - running=$($KUBECTL get pods -n "$ns" --no-headers 2>/dev/null | grep -c "^[^ ]* *[0-9]*/[0-9]* *Running" || echo 0) - - if [ "$total" -eq 0 ]; then + local pods_output total running + pods_output=$($KUBECTL get pods -n "$ns" --no-headers 2>/dev/null) + if [ -z "$pods_output" ]; then warn "$label — namespace vide ou inaccessible" return fi + total=$(echo "$pods_output" | wc -l) + running=$(echo "$pods_output" | grep -c " Running ") || running=0 if [ "$running" -eq "$total" ]; then check_ok "$label — $running/$total Running" else check_fail "$label — $running/$total Running" - $KUBECTL get pods -n "$ns" --no-headers 2>/dev/null \ + echo "$pods_output" \ | grep -v " Running " \ | awk '{printf " %-45s %s\n", $1, $3}' \ | head -6 @@ -419,11 +419,32 @@ cmd_start() { if [ $k8s_up -gt 0 ]; then local ready - ready=$($KUBECTL get nodes --no-headers 2>/dev/null | grep -c " Ready" || echo 0) + ready=$($KUBECTL get nodes --no-headers 2>/dev/null | grep -c " Ready") || ready=0 echo "" echo "[ cluster k8s — santé pods ]" if [ "$ready" -gt 0 ]; then check_ok "Nœuds — $ready/3 Ready" + + # Uncordon automatique si nœuds SchedulingDisabled (séquelle d'un funk-stop --k8s) + local uncordoned=0 + for name in "${K8S_NAMES[@]}"; do + if $KUBECTL get node "$name" --no-headers 2>/dev/null | grep -q "SchedulingDisabled"; then + $KUBECTL uncordon "$name" 2>/dev/null && ok "$name — uncordonné" || true + uncordoned=$((uncordoned + 1)) + fi + done + + # Après uncordon : attendre que les pods infra se re-schedulisent + if [ $uncordoned -gt 0 ]; then + info "Attente déploiement pods après uncordon (jusqu'à 2 min)..." + local sched_elapsed=0 + until [ "$($KUBECTL get pods -n infra --no-headers 2>/dev/null | grep -c " Running ")" -ge 1 ] \ + || [ $sched_elapsed -ge 120 ]; do + sleep 10; sched_elapsed=$((sched_elapsed + 10)) + echo -ne " → Attente pods... ${sched_elapsed}s\r" + done; echo "" + fi + check_k8s_workloads else warn "Nœuds joignables mais pas encore Ready"