🌳
pt0/deployF/k8sF/read2ResourceF.mts
3import { getKubeApis } from './getApisF.mts'
8export const read2Resource = async ({resource, cluster_name}: WithClusterAndResource) => {
9 const offlineReason = getOfflineReason(cluster_name)
10 if (offlineReason) return // known-down cluster: reads behave as "not found" rather than hanging
11 const {objectApi} = await getKubeApis({cluster_name})
13 try {
14 const resp = await withKubeRetry(() => objectApi.read(resource), cluster_name)
15 return resp
16 // console.log('readResource', resource.metadata.name, resp.response.statusCode)
17 // if (resp.response.statusCode == 200) return resp.body
18 } catch(err: unknown) {
19 const e = err as {body?: string}
20 if (!e.body) throw err
21 if (e.body.trim() == '404 page not found') return
22 const {reason} = json1Parse(e.body) as { reason?: string }
23 if (reason == 'NotFound') return
24 throw new PtErr('!read2Resource', {err, reason})
25 }
26 return null