Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/cloudtty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default function (): OperationHandlerArray {
},
]
const del: Operation = [
({ otomi, body }: OpenApiRequestExt, res) => {
async ({ otomi, body }: OpenApiRequestExt, res): Promise<void> => {
debug(`deleteCloudtty`)
otomi.deleteCloudtty(body)
await otomi.deleteCloudtty(body)
res.json({})
},
]
Expand Down
13 changes: 6 additions & 7 deletions src/k8s_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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) {
Expand Down
6 changes: 5 additions & 1 deletion src/otomi-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Workload> {
Expand Down