Stabilize UAT API pod selection

This commit is contained in:
hz
2026-07-23 17:03:02 -05:00
parent 32c455bba0
commit 0ec486f132
+23 -7
View File
@@ -72,16 +72,32 @@ kubectl rollout status deployment/step3-api -n "${KUBE_NAMESPACE}" --timeout=240
kubectl get --raw "/api/v1/namespaces/${KUBE_NAMESPACE}/services/step3-api:http/proxy/readyz" >/dev/null
if [ "${DEPLOYMENT_ENVIRONMENT}" = "uat" ]; then
# A completed old replica can briefly remain visible immediately after a
# rollout. Select the newest pod that is both Running and container-ready
# instead of relying on the first item returned by Kubernetes.
PROMOTION_SUCCEEDED=0
for attempt in 1 2 3; do
API_POD="$(kubectl get pods -n "${KUBE_NAMESPACE}" -l app=step3-api \
--field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')"
if [ -z "${API_POD}" ]; then
echo "No running API pod is available for dynamic question promotion." >&2
exit 1
fi
kubectl exec -n "${KUBE_NAMESPACE}" "${API_POD}" -- \
--field-selector=status.phase=Running \
--sort-by=.metadata.creationTimestamp \
-o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.containerStatuses[0].ready}{"\n"}{end}' \
| awk '$2 == "true" { name = $1 } END { print name }')"
if [ -n "${API_POD}" ] \
&& kubectl wait -n "${KUBE_NAMESPACE}" --for=condition=Ready "pod/${API_POD}" --timeout=60s \
&& kubectl exec -n "${KUBE_NAMESPACE}" "${API_POD}" -- \
dotnet QuestionsApi.dll promote-dynamic-questions \
--source /app/content/dynamic_questions \
--apply
--apply; then
PROMOTION_SUCCEEDED=1
break
fi
echo "Dynamic question promotion attempt ${attempt} did not find a stable ready API pod; retrying." >&2
sleep 2
done
if [ "${PROMOTION_SUCCEEDED}" -ne 1 ]; then
echo "Dynamic question promotion failed after 3 attempts." >&2
exit 1
fi
fi
kubectl rollout status deployment/step3-web -n "${KUBE_NAMESPACE}" --timeout=240s