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:
Nikola Jokic
2024-02-05 14:40:15 +01:00
committed by GitHub
parent 921be5b85f
commit 50e14cf868

View File

@@ -228,8 +228,10 @@ 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) {
exec
.exec(
namespace(), namespace(),
podName, podName,
containerName, containerName,
@@ -253,6 +255,9 @@ export async function execPodStep(
} }
} }
) )
// If exec.exec fails, explicitly reject the outer promise
// eslint-disable-next-line github/no-then
.catch(e => reject(e))
}) })
} }