🌳
pt0/deployF/k8sF/coalActionsF/index.mts
4import yaml from 'js-yaml'
5import * as _ from 'lodash-es'
9export const resources = () => {
10 let {resourcesA} = getReqKubeCoalesceCtx()
12 resourcesA = _.reject(resourcesA, isMutableRes)
14 const filterName = getProcArgv()[3] as 'pvc' | 'deploy' | undefined
15 const filtersH = {
16 pvc: isPvc, deploy: isKubeDeploy,
17 }
18 const filterFnc = filterName ? filtersH[filterName] : undefined
19 if (filterFnc) {
20 resourcesA = _.filter(resourcesA, filterFnc)
21 }
23 resourcesA = kubeDeepOmitUndefEmptyArr(resourcesA)
25 const outFmt = (() => {
26 const argv = getProcArgv()
27 const dashOIdx = _.indexOf(argv, '-o')
28 if (dashOIdx == -1) return 'json'
29 return argv[dashOIdx + 1]
30 })()
32 if (process.env.PTNODE_SAVE_EXAMPLE) {
33 for (const item of resourcesA as any[]) {
34 if (item?.kind !== 'Secret') continue
35 for (const field of ['data', 'stringData']) {
36 if (!item[field]) continue
37 for (const key of Object.keys(item[field])) item[field][key] = '<omitted>'
38 }
39 }
40 }
41 if (outFmt == 'json') {
42 console.log(JSON.stringify(resourcesA, null, 2))
43 // console.log(
44 // util.inspect(resourcesA, {showHidden: false, depth: null, colors: false})
45 // )
46 } else if (outFmt == 'yaml') {
47 console.log(
48 _.chain(resourcesA).map(yaml.dump).join("\n---\n").value()
49 )
50 } else {
51 betLog(resourcesA)
52 }