Skip to content

Commit

Permalink
fix(k8s): unexpected error when losing exec WS connection
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jul 16, 2021
1 parent e13365e commit 9400d63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
34 changes: 11 additions & 23 deletions core/src/plugins/kubernetes/api.ts
Expand Up @@ -725,21 +725,6 @@ export class KubeApi {
}

const execHandler = new Exec(this.config, new WebSocketHandler(this.config))
let status: V1Status

const ws = await execHandler.exec(
namespace,
podName,
containerName,
command,
_stdout,
_stderr,
stdin || null,
tty,
(_status) => {
status = _status
}
)

return new Promise((resolve, reject) => {
let done = false
Expand All @@ -762,14 +747,17 @@ export class KubeApi {
}, timeoutSec * 1000)
}

ws.on("error", (err) => {
!done && reject(err)
done = true
})

ws.on("close", () => {
finish(false, getExecExitCode(status))
})
execHandler
.exec(namespace, podName, containerName, command, _stdout, _stderr, stdin || null, tty, (status) => {
finish(false, getExecExitCode(status))
})
.then((ws) => {
ws.on("error", (err) => {
!done && reject(err)
done = true
})
})
.catch(reject)
})
}

Expand Down
4 changes: 4 additions & 0 deletions core/src/plugins/kubernetes/status/pod.ts
Expand Up @@ -174,6 +174,10 @@ export async function getFormattedPodLogs(api: KubeApi, namespace: string, pods:
}

export function getExecExitCode(status: V1Status) {
if (!status) {
return 1
}

let exitCode = 0

if (status.status !== "Success") {
Expand Down

0 comments on commit 9400d63

Please sign in to comment.