🌳
pt0/deployF/k8sF/initialSetupF/certmanager/leWcCertF.mts
1import * as _ from 'lodash-es'
8export const leIssuerName = 'le-wildcard-issuer'
10export const isCertReady = async ({name, namespace = 'default', cluster_name}: {name: string, namespace?: string, cluster_name: string}): Promise<boolean> => {
11 const cert = await read2Resource({
12 cluster_name,
13 resource: {apiVersion: 'cert-manager.io/v1', kind: 'Certificate', metadata: {name, namespace}},
14 }) as {status?: {conditions?: {type: string, status: string}[]}} | null
15 const ready = (cert?.status?.conditions || []).find(c => c.type === 'Ready')
16 return !!ready && ready.status === 'True'
19export const awaitCertsReady = async ({namespace = 'default', timeoutMs = 5 * 60 * 1000} = {}) => {
20 const {klustCertsH, cluster_name} = getKlusterCtx()
21 assertDefined(klustCertsH)
23 const certNames = Object.keys(klustCertsH)
24 process.stdout.write(`waiting for certs: ${certNames.join(', ')}`)
26 await pollUntil({
27 predicate: async () => {
28 for (const name of certNames) {
29 if (!await isCertReady({name, namespace, cluster_name})) return true
30 }
31 return false
32 },
33 intervalMs: 10000,
34 timeoutMs,
35 timeoutLabel: `certs ready (${certNames.join(', ')})`,
36 })
37 console.log(' ready')
40export const k8sCerts = async ({namespace = 'default'} = {}) => {
41 const {klustCertsH} = getKlusterCtx()
43 assertDefined(klustCertsH)
45 const resources = _.map(klustCertsH, (dnsNamesRaw, name) => {
46 const dnsNames = Array.isArray(dnsNamesRaw) ? dnsNamesRaw : [dnsNamesRaw]
47 return {
48 apiVersion: 'cert-manager.io/v1',
49 kind: 'Certificate',
50 metadata: {
51 name,
52 namespace,
53 },
54 spec: {
55 dnsNames,
56 issuerRef: {
57 kind: 'ClusterIssuer',
58 name: leIssuerName
59 },
60 secretName: name
61 }
62 }
63 })
64 await resourcesAction({resources})