1import * as _ from 'lodash-es' 2import type { V1Pod } from '@kubernetes/client-node' 8 labels?: Record<string, string> 12export const resourcesAsPods = <T extends object>(resources: T[]) => { 13 return _.map(resources, (res) => { 14 (res as T & {apiVersion: string, kind: string}).apiVersion = 'v1' 15 ;(res as T & {apiVersion: string, kind: string}).kind = 'Pod' 20const podToInfo = (pod: V1Pod) => { 23 const podName = pod.metadata.name 24 const containerNames = _.map(pod.spec.containers, 'name') as string[] 25 const containerName = containerNames[0] 26 const git_sha = pod.metadata?.labels?.git_sha 27 return {podName, containerName, containerNames, git_sha} 30export const getSinglePod = async (props: GetSinglePodProps) => { 31 // Don't pass limit to k8s API - it applies before sorting, so we'd get arbitrary pod instead of newest 32 const pod = (await get1ClusterPods({...props, labels: props.labels, fuzzyPodName: props.fuzzyPodName}))[0] as V1Pod | undefined 37export const getAllPods = async (props: GetSinglePodProps) => { 39 return _.map(pods, podToInfo)