Skip to content

Commit

Permalink
fix(k8s): attempt execing on running pod (#5782)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
Try to choose a running Pod for execing into. Without this, users might
get the following error persistently if the first pod happened to be
crashlooping:

```
run.test✖ Failed processing Run type=kubernetes-exec name=test (took 12.35 sec). This is what happened:

────────────────────────────────────────────────────────────────────────────────────────────────────
Error while performing Kubernetes API operation Pod exec: WebsocketError

Unexpected server response: 500
────────────────────────────────────────────────────────────────────────────────────────────────────

```

**Which issue(s) this PR fixes**:

Fixes #5729

**Special notes for your reviewer**:
  • Loading branch information
stefreak committed Feb 26, 2024
1 parent 75dfcd1 commit 8b94e49
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/plugins/kubernetes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ export async function execInWorkload({
const api = await KubeApi.factory(log, ctx, provider)
const pods = await getCurrentWorkloadPods(api, namespace, workload)

const pod = pods[0]
const runningPods = pods.filter((p) => checkPodStatus(p) === "ready")
if (runningPods.length === 0) {
throw new DeploymentError({
message: `No running pods found for ${getResourceKey(workload)}`,
})
}

const pod = sample(runningPods)

if (!pod) {
// This should not happen because of the prior status check, but checking to be sure
Expand Down

0 comments on commit 8b94e49

Please sign in to comment.