5type PodHealthResult = { healthy: true } | { healthy: false, message: string } 7export const checkPodsHealthy = async ({ name, cluster_name, minReplicas = 1 }: { name: string, cluster_name: string, minReplicas?: number }): Promise<PodHealthResult> => { 8 const deployment = await read2Resource({resource: {apiVersion: 'apps/v1', kind: 'Deployment', metadata: {name, namespace: 'default'}} as any, cluster_name}) as 9 {spec?: {template?: {metadata?: {labels?: {git_sha?: string}}}}} | undefined 10 const deployGitSha = deployment?.spec?.template?.metadata?.labels?.git_sha 12 const allPods = await get1ClusterPods({ cluster_name, labels: { name }, fuzzyPodName: undefined, limit: undefined }) 13 const pods = deployGitSha ? allPods.filter(pod => (pod.metadata?.labels as any)?.git_sha === deployGitSha) : allPods 15 if (pods.length === 0) { 16 return { healthy: false, message: `no pods found for ${name}` } 19 const readyPods = pods.filter(pod => { 23 if (readyPods.length < minReplicas) { 24 return { healthy: false, message: `${readyPods.length}/${minReplicas} pods ready for ${name}` } 27 const badPods = pods.filter(pod => { 28 const phase = pod.status?.phase 29 return phase === 'Failed' || phase === 'Unknown' 32 if (badPods.length > 0) { 33 return { healthy: false, message: `${badPods.length} pods in bad state for ${name}` } 36 return { healthy: true }