🌳
pt0/deployF/deriveDbNodePortsAI.mts
1import * as _ from 'lodash-es'
2import { getPlainNoMappedSec, type secretNameType } from '../serverF/secretsF/getPlainSecAI.mts'
3import { type envConfType } from '../serverF/envConfF.mts'
8import type { AppCfg } from './k8sF/ctxF/appCfgCtxF.mts'
10export const deriveDbNodePorts = (appConfig: AppCfg) => {
11 const {secretsMapping = {}} = (appConfig.envConf ?? {}) as envConfType
12 const dbHosts = _.chain(secretsMapping).map((mapToName: string, mapFromName: string) => {
13 if (mapToName == disabledSecret) return
14 if (!_.endsWith(mapFromName, '_qs')) return
15 const dbQs = getPlainNoMappedSec(mapToName as secretNameType)
16 return qsToUriH(dbQs).svcName
17 }).compact().uniq().value()
19 const {allNodePorts} = appConfig
20 if (dbHosts.length === 0) return
22 assertDefined(allNodePorts, {appConfig})
24 const pickKeys = _.chain(dbHosts).map((svcName: string) => {
25 return _.map(allNodePorts, (klustSvcsH: Record<string, number>, clusterName: string) => {
26 const nodePortNo = klustSvcsH[svcName]
27 if (!nodePortNo) return
28 return [
29 [clusterName, 'nodeIpsExtHost'].join('.'),
30 [clusterName, svcName].join('.'),
31 ]
32 })
33 }).flattenDeep().compact().value() as unknown as string[]
35 const nodePorts = _.pick(allNodePorts, pickKeys)
36 throwIf(() => _.isEmpty(nodePorts), {allNodePorts, nodePorts, pickKeys, dbHosts})