🌳
pt0/deployF/k8sF/ingressF.mts
1import * as _ from 'lodash-es'
6export const ctxOptUseIgNameFromHn = genContext()
8type IngressTlsEntry = { hosts: string[], secretName: string }
10type IngressTmplProps = {
11 ingressClassName?: string
12 hostname?: string
13 hostnameA?: string[]
14 name: string
17export const ingressTmpl = ({ingressClassName='nginx', hostname, hostnameA, name}: IngressTmplProps): { tls: IngressTlsEntry[], ingressClassName: string } => {
18 hostnameA ||= _.castArray(hostname)
20 const certMatchA = _.map(hostnameA, findCertForHostname)
22 const allHaveCert = _.compact(certMatchA).length == certMatchA.length
23 const noneHaveCert = _.compact(certMatchA).length == 0
25 let tls: IngressTlsEntry[]
26 if (allHaveCert) {
27 tls = _.map(hostnameA, (host) => {
28 const {certName} = findCertForHostname(host)!
29 return {hosts: [host], secretName: certName}
30 })
31 } else if (noneHaveCert) {
32 tls = [{
33 hosts: hostnameA,
34 secretName: (
35 ctxOptUseIgNameFromHn.getStore() ? hostname! : name + '-tls'
36 ),
37 }]
38 } else {
39 return throPtErr('someWcHn??', {certMatchA, allHaveCert, noneHaveCert})
40 }
42 return {
43 tls, ingressClassName,
44 }