diff --git a/src/api/cloudtty.ts b/src/api/cloudtty.ts index f34075048..e89f13ee8 100644 --- a/src/api/cloudtty.ts +++ b/src/api/cloudtty.ts @@ -13,9 +13,9 @@ export default function (): OperationHandlerArray { }, ] const del: Operation = [ - ({ otomi, body }: OpenApiRequestExt, res) => { + async ({ otomi, body }: OpenApiRequestExt, res): Promise => { debug(`deleteCloudtty`) - otomi.deleteCloudtty(body) + await otomi.deleteCloudtty(body) res.json({}) }, ] diff --git a/src/k8s_operations.ts b/src/k8s_operations.ts index 6318d8daa..b0dba884c 100644 --- a/src/k8s_operations.ts +++ b/src/k8s_operations.ts @@ -77,20 +77,19 @@ export async function watchPodUntilRunning(namespace: string, podName: string) { return true } -export async function checkPodExists(namespace: string, podName: string) { - let isRunning = false +export async function checkPodExists(namespace: string, podName: string): Promise { const kc = new k8s.KubeConfig() kc.loadFromDefault() const k8sApi = kc.makeApiClient(k8s.CoreV1Api) try { const res = await k8sApi.readNamespacedPodStatus(podName, namespace) - isRunning = res.body.status?.phase === 'Running' - } catch (error) { - debug('checkPodExist error:', error) + return res.body.status?.phase === 'Running' + } catch (err) { + const errorMessage = err.response?.body?.message ?? err.response?.body?.reason ?? 'Error checking if pod exists' + debug(`Failed to check pod status for ${podName} in namespace ${namespace}: ${errorMessage}`) + return false } - - return isRunning } export async function k8sdelete({ emailNoSymbols, isAdmin, userTeams }: Cloudtty) { diff --git a/src/otomi-stack.ts b/src/otomi-stack.ts index 84caf23a4..5f0ea1387 100644 --- a/src/otomi-stack.ts +++ b/src/otomi-stack.ts @@ -978,7 +978,11 @@ export default class OtomiStack { } async deleteCloudtty(data: Cloudtty) { - if (await checkPodExists('team-admin', `tty-${data.emailNoSymbols}`)) await k8sdelete(data) + try { + if (await checkPodExists('team-admin', `tty-${data.emailNoSymbols}`)) await k8sdelete(data) + } catch (error) { + debug('Failed to delete cloudtty') + } } getTeamWorkloads(teamId: string): Array {