mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 00:26:44 +00:00
Switch exec pod promise to reject on websocket error (#127)
* Switch exec pod promise to reject on websocket error * Fix incorrectly resolved merge conflict * Apply suggestions from code review Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> --------- Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com>
This commit is contained in:
@@ -228,31 +228,36 @@ export async function execPodStep(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const exec = new k8s.Exec(kc)
|
const exec = new k8s.Exec(kc)
|
||||||
command = fixArgs(command)
|
command = fixArgs(command)
|
||||||
await new Promise(async function (resolve, reject) {
|
// Exec returns a websocket. If websocket fails, we should reject the promise. Otherwise, websocket will call a callback. Since at that point, websocket is not failing, we can safely resolve or reject the promise.
|
||||||
await exec.exec(
|
await new Promise(function (resolve, reject) {
|
||||||
namespace(),
|
exec
|
||||||
podName,
|
.exec(
|
||||||
containerName,
|
namespace(),
|
||||||
command,
|
podName,
|
||||||
process.stdout,
|
containerName,
|
||||||
process.stderr,
|
command,
|
||||||
stdin ?? null,
|
process.stdout,
|
||||||
false /* tty */,
|
process.stderr,
|
||||||
resp => {
|
stdin ?? null,
|
||||||
// kube.exec returns an error if exit code is not 0, but we can't actually get the exit code
|
false /* tty */,
|
||||||
if (resp.status === 'Success') {
|
resp => {
|
||||||
resolve(resp.code)
|
// kube.exec returns an error if exit code is not 0, but we can't actually get the exit code
|
||||||
} else {
|
if (resp.status === 'Success') {
|
||||||
core.debug(
|
resolve(resp.code)
|
||||||
JSON.stringify({
|
} else {
|
||||||
message: resp?.message,
|
core.debug(
|
||||||
details: resp?.details
|
JSON.stringify({
|
||||||
})
|
message: resp?.message,
|
||||||
)
|
details: resp?.details
|
||||||
reject(resp?.message)
|
})
|
||||||
|
)
|
||||||
|
reject(resp?.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
// If exec.exec fails, explicitly reject the outer promise
|
||||||
|
// eslint-disable-next-line github/no-then
|
||||||
|
.catch(e => reject(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user