🌳
pt0/deployF/k8sF/resourcesActionCoreF.mts
1import { getKlusterCtx, type KubeResource } from './ctxF/klusterCtxF.mts'
3import { isPvc } from './isKubeResF.mts'
17type ResourcesActionCoreProps = {
18 resources: KubeResource[]
19 action?: string
20 cluster_name?: string
21 noDelPvcs?: boolean
22 skipTlsCheck?: boolean
23 isQuiet?: boolean
26export const resourcesActionCore = async ({
27 resources, action, cluster_name,
28 noDelPvcs=true, skipTlsCheck=false, isQuiet=false,
29}: ResourcesActionCoreProps) => {
30 const ctx = getKlusterCtx()
31 action ||= ctx.action
32 cluster_name ||= ctx.cluster_name
34 assertDefined(cluster_name)
36 if (isApplyishAction(action) && cliFlag('--history')) {
37 await applyHistoryGuard(getAppCfg().importMetaUrl)
38 return
39 }
41 if (!skipTlsCheck && isApplyishAction(action)) {
42 await checkIngressTlsSecretsExist({resources, cluster_name})
43 }
45 const ret = await allPromCalls(resources, (resource) => {
46 return res1Action({resource, action, cluster_name, noDelPvcs})
47 })
49 if (isApplyishAction(action)) {
50 const summaryLines = fmtApplySummary(ret as any)
51 if (!isQuiet) for (const {cluster, action: act, line} of summaryLines) {
52 logElapsed(`k8s ${cluster} ${actionLabel(act)}: ${line}`)
53 }
54 }
56 if (action === 'delete') {
57 const {deleted} = fmtDeleteSummary(ret as any)
59 for (const {cluster, line} of deleted) {
60 if (!isQuiet) process.stdout.write(`k8s ${cluster} delete: ${line}`)
61 await allPromCalls(resources, async (resource) => {
62 if (noDelPvcs && isPvc(resource)) return
63 const resName = `${resource.kind} ${resource.metadata?.name}`
64 await pollUntil({predicate: () => read2Resource({resource, cluster_name}), timeoutLabel: `delete ${resName}`, isQuiet})
65 })
66 if (!isQuiet) console.log(' done')
67 }
68 }
70 return ret