Skip to content

fix(k8s): diagnose the failed deployment before the rollback deletes it - #214

Open
ignacioboud wants to merge 1 commit into
betafrom
fix/rollback-diagnose-before-delete
Open

fix(k8s): diagnose the failed deployment before the rollback deletes it#214
ignacioboud wants to merge 1 commit into
betafrom
fix/rollback-diagnose-before-delete

Conversation

@ignacioboud

Copy link
Copy Markdown
Contributor

Problem

Every rollback ended with the same block, regardless of what happened:

⚠️  Application Startup Issue Detected
💡 Possible causes:
   Your application was unable to start within the expected timeframe
🔧 How to fix:
   1. Port Configuration: Ensure your application listens on port 8080
   ...

Including manual rollbacks of applications that started perfectly well.

Cause

print_deployment_error_hints was the last step of rollback.yaml, running after delete deployment. The diagnosis it performs reads the failed deployment's pods:

kubectl get pods -n "$K8S_NAMESPACE" -l "deployment_id=${DEPLOYMENT_ID}"

Those pods were deleted two steps earlier, so the query always came back empty. With no FAILURE_REASON, SUGGESTED_FIX stayed empty, and the script's fallback for "nothing detected" printed the generic block:

if [[ -z "$SUGGESTED_FIX" ]]; then
    print_generic_hints
fi

The specific diagnosis — image pull errors, crash loops, OOM kills, failed health checks, each with a targeted suggested fix — could never run in a rollback.

Change

Move the hints step ahead of the deletion. One step reordered, no script changes.

The failed deployment's pods are still present at that point under both strategies:

  • blue/greenscale_deployments is a no-op; its entire body sits inside if [ "$DEPLOY_STRATEGY" = "rolling" ].
  • rollingbuild_context:115 floors green replicas at MIN_REPLICAS after the traffic-based calculation, with the comment "Apply minimum after the blue replica calculation so we do not remove pods with 0% traffic switch".

Not addressed here

A manual rollback of a healthy deployment will still reach the generic block, because "nothing detected" and "nothing was wrong" are indistinguishable to the fallback. Separating them means changing the shared script's contract — wait_deployment_active sources it on deploy timeout, where the generic hints are the right output. That deserves its own change.

Tests

k8s BATS suite green (38 tests). Workflow YAMLs have no unit tests in this repo; the file was validated by parsing it and asserting the resulting step order.

🤖 Generated with Claude Code

print_deployment_error_hints ran as the last step of the rollback workflow,
after `delete deployment` had already removed the pods it inspects
(kubectl get pods -l deployment_id=$DEPLOYMENT_ID). With no pods to read, the
specific diagnosis was always empty, and the script's fallback for "nothing
detected" printed the generic "Application Startup Issue Detected" block on
every rollback — including manual ones where nothing had failed to start.

Move the step ahead of the deletion. The failed deployment's pods are still
present there under both strategies: scale_deployments is a no-op for
blue/green, and for rolling build_context floors green replicas at
MIN_REPLICAS precisely so a 0% traffic switch does not remove them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant