🌳
pt0/deployF/cnpgF/awaitCnpgReadyAI.mts
5export const cnpgSystemNs = 'cnpg-system'
7const isNsActive = async ({cluster_name}: {cluster_name: string}): Promise<boolean> => {
8 const ns = await read2Resource({
9 cluster_name,
10 resource: {apiVersion: 'v1', kind: 'Namespace', metadata: {name: cnpgSystemNs}},
11 }) as {status?: {phase?: string}} | null
12 return ns?.status?.phase === 'Active'
15const isWebhookServing = async ({cluster_name}: {cluster_name: string}): Promise<boolean> => {
16 const ep = await read2Resource({
17 cluster_name,
18 resource: {apiVersion: 'v1', kind: 'Endpoints', metadata: {name: 'cnpg-webhook-service', namespace: cnpgSystemNs}},
19 }) as {subsets?: {addresses?: unknown[]}[]} | null
20 return !!ep?.subsets?.some(s => s.addresses?.length)
23export const awaitCnpgNsActive = async ({timeoutMs = 60 * 1000} = {}) => {
24 const {cluster_name} = getKlusterCtx()
25 await pollUntil({
26 predicate: async () => !await isNsActive({cluster_name}),
27 intervalMs: 2000,
28 timeoutMs,
29 timeoutLabel: `namespace ${cnpgSystemNs} active`,
30 })
33export const awaitCnpgWebhookReady = async ({timeoutMs = 3 * 60 * 1000} = {}) => {
34 const {cluster_name} = getKlusterCtx()
35 process.stdout.write('waiting for cnpg webhook endpoints...')
36 await pollUntil({
37 predicate: async () => !await isWebhookServing({cluster_name}),
38 intervalMs: 3000,
39 timeoutMs,
40 timeoutLabel: 'cnpg webhook endpoints ready',
41 })
42 console.log(' ready')