Add detailed debug output to API verify-deploy

Show deployment spec image to confirm patch worked, dump all pod
details (image, ready, phase, restarts, reason) on attempts 1/10/30
and on failure. This will reveal whether pods are crashlooping, stuck
in Pending, or if the deployment patch didn't take effect.
This commit is contained in:
Viktor Barzin 2026-02-22 18:35:20 +00:00
parent 67d4ab3821
commit 268f4fd272
No known key found for this signature in database
GPG key ID: 0EB088298288D958

View file

@ -284,21 +284,36 @@ steps:
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
EXPECTED_IMAGE="viktorbarzin/realestatecrawler:${DRONE_BUILD_NUMBER}"
BASE_API="https://kubernetes:6443/api/v1/namespaces/realestate-crawler/pods"
DEPLOY_API="https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
for DEPLOY in realestate-crawler-api realestate-crawler-celery realestate-crawler-celery-beat; do
echo "Verifying $DEPLOY..."
PODS_API="$BASE_API?labelSelector=app%3D$DEPLOY"
# Check deployment spec to confirm patch took effect
DEPLOY_IMAGE=$(curl -sfk "$DEPLOY_API/$DEPLOY" \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" | \
jq -r '.spec.template.spec.containers[0].image' 2>/dev/null)
echo " Deployment spec image: $DEPLOY_IMAGE"
FOUND=0
for i in $(seq 1 60); do
RAW=$(curl -sfk "$PODS_API" \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json")
# Debug: show all pod images and status on first attempt
if [ "$i" -eq 1 ]; then
echo " DEBUG: All pods for $DEPLOY:"
echo "$RAW" | jq -r '[.items[] | {name: .metadata.name, image: .spec.containers[0].image, ready: (.status.containerStatuses[]? | .ready), phase: .status.phase}] | .[] | " \(.name) image=\(.image) ready=\(.ready) phase=\(.phase)"' 2>/dev/null || echo " (no pods found)"
# Debug: show all pod images and status periodically
if [ "$i" -eq 1 ] || [ "$i" -eq 10 ] || [ "$i" -eq 30 ]; then
echo " DEBUG (attempt $i): All pods for $DEPLOY:"
echo "$RAW" | jq -r '[.items[] | {
name: .metadata.name,
image: .spec.containers[0].image,
ready: ([.status.containerStatuses[]? | .ready] | first // "unknown"),
phase: .status.phase,
restarts: ([.status.containerStatuses[]? | .restartCount] | first // 0),
reason: ([.status.containerStatuses[]? | .state | to_entries[] | .value.reason // empty] | first // "running")
}] | .[] | " \(.name) image=\(.image) ready=\(.ready) phase=\(.phase) restarts=\(.restarts) reason=\(.reason)"' 2>/dev/null || echo " (no pods or parse error)"
fi
RESULT=$(echo "$RAW" | \
@ -321,6 +336,15 @@ steps:
done
if [ "$FOUND" -ne 1 ]; then
echo " FINAL DEBUG: All pods for $DEPLOY:"
echo "$RAW" | jq -r '[.items[] | {
name: .metadata.name,
image: .spec.containers[0].image,
ready: ([.status.containerStatuses[]? | .ready] | first // "unknown"),
phase: .status.phase,
restarts: ([.status.containerStatuses[]? | .restartCount] | first // 0),
reason: ([.status.containerStatuses[]? | .state | to_entries[] | .value.reason // empty] | first // "running")
}] | .[] | " \(.name) image=\(.image) ready=\(.ready) phase=\(.phase) restarts=\(.restarts) reason=\(.reason)"' 2>/dev/null || echo " (no pods or parse error)"
echo "ERROR: No new ready pod for $DEPLOY with image $EXPECTED_IMAGE appeared within 5 minutes"
exit 1
fi