From 952b179d9a06d5918e2727720061a298a13d1789 Mon Sep 17 00:00:00 2001 From: Per Magnus Petersen Date: Wed, 30 Sep 2026 17:52:41 +0200 Subject: [PATCH] Wait for btcdata pod readiness before reconnecting tunnel --- scripts/fetch-year.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/fetch-year.sh b/scripts/fetch-year.sh index 5675f9e..24b3e1b 100755 --- a/scripts/fetch-year.sh +++ b/scripts/fetch-year.sh @@ -50,6 +50,23 @@ trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM +wait_for_pod() { + local selector + # Use the service's selector rather than assuming a particular pod label. + if ! selector=$(kubectl -n sejs get svc btcdata --request-timeout=10s \ + -o go-template='{{range $key, $value := .spec.selector}}{{$key}}={{$value}},{{end}}'); then + return 1 + fi + selector=${selector%,} + if [[ -z $selector ]]; then + echo "Service sejs/btcdata has no pod selector." >&2 + return 1 + fi + echo "Waiting up to 5 minutes for btcdata pods to become Ready..." >&2 + kubectl -n sejs wait --for=condition=Ready pod --selector="$selector" \ + --timeout=300s --request-timeout=310s >&2 +} + start_forward() { local attempt cleanup @@ -57,6 +74,10 @@ start_forward() { echo "Service unavailable on localhost:4101 and kubectl is not installed." >&2 return 1 fi + if ! wait_for_pod; then + echo "btcdata pod readiness check failed; not opening a tunnel." >&2 + return 1 + fi echo "Starting kubectl port-forward for sejs/btcdata..." >&2 kubectl -n sejs port-forward svc/btcdata 4101:4101 >&2 & forward_pid=$!