🌳
pt0/deployF/k8sF/genericExtNameSvcF.mts
10type ExtNameSvcProps = { extHostname: string, externalName: string }
12export const genericExtNameSvc = ({extHostname, externalName}: ExtNameSvcProps) => {
13 return {
14 kind: 'Service',
15 apiVersion: 'v1',
16 metadata: {
17 name: dash1Case(extHostname),
18 annotations: {
19 'external-dns.alpha.kubernetes.io/hostname': extHostname,
20 }
21 },
22 spec: {
23 type: 'ExternalName',
24 externalName
25 }
26 }
29type SetKlusterWcProps = { action: string, ip?: string }
31export const doSetKlusterWcHnIp = async ({action, ip}: SetKlusterWcProps) => {
32 if (!ip) {
33 console.log('skipping doSetKlusterWcHnIp - ip not provided')
34 return
35 }
36 const {cluster_name, klusterVipHostname, clusterVip, klustCertsH, cfApiKeySecretName, domainNames} = getKlusterCtx()
38 const exposeDnsNames = Object.values(klustCertsH).flat() as string[]
39 throwIf(() => exposeDnsNames.length === 0, {cluster_name, klustCertsH})
41 const headers = getCfHeaders({cfApiKeySecretName, required: false})
42 const claimStore = headers && domainNames && domainNames.length ? mkCfTxtClaimStore({headers, domainNames}) : undefined
43 const isApply = action !== 'delete'
45 const resources = []
46 for (const dnsName of exposeDnsNames) {
47 if (claimStore && isApply && dnsName.startsWith('*.')) {
48 const {claimed} = await acquireClaim({store: claimStore, claimKey: wcClaimKey(dnsName), owner: cluster_name})
49 if (!claimed) { betLog({skippedWcClaim: dnsName, cluster_name}); continue }
50 }
51 resources.push(genericExtNameSvc({extHostname: dnsName, externalName: dnsName == klusterVipHostname ? clusterVip : ip}))
52 }
54 await resourcesAction({resources, action})
55 if (claimStore && isApply) await renewAllMyClaims({store: claimStore, owner: cluster_name})