🌳
pt0/deployF/k8sF/getPodStatusAI.mts
3import { type WithClusterName } from './ctxF/klusterCtxF.mts'
4import type { V1Pod } from '@kubernetes/client-node'
6type GetPodStatusProps = WithClusterName & {name: string}
8export const getPodStatusFromPod = (pod: V1Pod | undefined) => {
9 if (!pod) return null
10 const phase = pod.status?.phase ?? null
11 const containerStatus = pod.status?.containerStatuses?.[0]
12 const restarts = containerStatus?.restartCount ?? 0
13 const waitingReason = containerStatus?.state?.waiting?.reason ?? null
14 const ready = pod.status?.conditions?.find(c => c.type === 'Ready')?.status === 'True'
15 const pendingDetail = phase === 'Pending' ? getPendingReason(pod) : null
16 return {running: phase === 'Running' && ready, phase, restarts, waitingReason, ready, pendingDetail}
19export const getPodStatus = async ({cluster_name, name}: GetPodStatusProps) => {
20 const pods = await get1ClusterPods({cluster_name, labels: {name}, limit: 1})
21 return getPodStatusFromPod(pods[0])