🌳
pt0/deployF/k8sF/podsF/k8sPodsF.mts
1import * as _ from 'lodash-es'
8import type { V1Pod } from '@kubernetes/client-node'
10type Get1ClusterPodsProps = WithClusterName & { labels?: Record<string, string>, fuzzyPodName?: string, limit?: number }
11const get1Pods = get1ClusterPods as (props: Get1ClusterPodsProps) => Promise<V1Pod[]>
13export const getAppPods = async ({cluster_name, name}: WithClusterAndName) => {
14 return await get1Pods({cluster_name, labels: {name}})
17export const getMostRecentPod = async ({cluster_name, name}: WithClusterAndName) => {
18 let pods = await getAppPods({cluster_name, name})
19 if (!pods.length) {
20 // Fallback to fuzzy pod name match for CLI usage (e.g. `flogs nimbus` matching `nimbus-mainnet-...`)
21 pods = await get1Pods({cluster_name, fuzzyPodName: name})
22 }
23 const pod = _.first(pods)
25 const podName = pod.metadata?.name
26 assertDefined(podName)
27 return podName
30export const delPodFuzzy = async ({name, cluster_name}: WithClusterAndName) => {
31 const podName = await getMostRecentPod({cluster_name, name})
32 return await eptKubeCli([cluster_name, 'delete', 'pod', podName])
35type DelMatchingPodsProps = WithClusterName & { labels: Record<string, string> }
36export const delMatchingPods = async ({cluster_name, labels}: DelMatchingPodsProps) => {
38 const resources = await get1Pods({cluster_name, labels})
39 throwIf(() => resources.length > 2)
40 await resourcesActionLite({resources, action: 'delete'})