Stabilize UAT API pod selection
This commit is contained in:
@@ -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
|
kubectl get --raw "/api/v1/namespaces/${KUBE_NAMESPACE}/services/step3-api:http/proxy/readyz" >/dev/null
|
||||||
|
|
||||||
if [ "${DEPLOYMENT_ENVIRONMENT}" = "uat" ]; then
|
if [ "${DEPLOYMENT_ENVIRONMENT}" = "uat" ]; then
|
||||||
API_POD="$(kubectl get pods -n "${KUBE_NAMESPACE}" -l app=step3-api \
|
# A completed old replica can briefly remain visible immediately after a
|
||||||
--field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')"
|
# rollout. Select the newest pod that is both Running and container-ready
|
||||||
if [ -z "${API_POD}" ]; then
|
# instead of relying on the first item returned by Kubernetes.
|
||||||
echo "No running API pod is available for dynamic question promotion." >&2
|
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 \
|
||||||
|
--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; 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
kubectl exec -n "${KUBE_NAMESPACE}" "${API_POD}" -- \
|
|
||||||
dotnet QuestionsApi.dll promote-dynamic-questions \
|
|
||||||
--source /app/content/dynamic_questions \
|
|
||||||
--apply
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kubectl rollout status deployment/step3-web -n "${KUBE_NAMESPACE}" --timeout=240s
|
kubectl rollout status deployment/step3-web -n "${KUBE_NAMESPACE}" --timeout=240s
|
||||||
|
|||||||
Reference in New Issue
Block a user