From 7364734713bd70649a4e1388b363ea5f85f54cb5 Mon Sep 17 00:00:00 2001 From: hermes Date: Mon, 9 Nov 2026 12:21:07 +1000 Subject: [PATCH] fix(ci): count the kubeconfig's clusters correctly The cluster-count guard I added used `grep -c '"name"'`, which counts LINES. The jsonpath output is a single line, so the count was 1 for a kubeconfig with clusters and 1 for one without - which made the guard reject every kubeconfig: ERROR: the kubeconfig has no cluster entries. The count is now done with `grep -o . | wc -l`, which counts occurrences rather than lines. Tested against both cases: - a real kubeconfig with a stale CA -> the CA is refreshed and kubectl works - a kubeconfig with no clusters -> refuses with a clear message --- scripts/kube-ca-refresh.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/kube-ca-refresh.sh b/scripts/kube-ca-refresh.sh index f80117b..a288a7f 100755 --- a/scripts/kube-ca-refresh.sh +++ b/scripts/kube-ca-refresh.sh @@ -56,8 +56,10 @@ if [ -z "$EXPECTED" ]; then fi # Guard against a kubeconfig with no clusters, or an empty one. -CLUSTER_COUNT=$(kubectl config view --raw -o jsonpath='{.clusters}' 2>/dev/null \ - | grep -c '"name"' || true) +# `grep -c` counts LINES, and the jsonpath output is a single line, so the +# count is done with grep -o and wc -l instead. +CLUSTER_COUNT=$(kubectl config view --raw -o jsonpath='{.clusters[*].name}' 2>/dev/null \ + | grep -o . | wc -l || true) if [ "${CLUSTER_COUNT:-0}" -eq 0 ]; then echo "ERROR: the kubeconfig has no cluster entries." >&2 echo " The KUBEC_CONFIG_BUILDX_NEW_2 secret looks wrong or empty." >&2