1import { fix1IngressPublishAddr } from '../k8sF/fix1IngressPublishAddrAI.mts'2import { getKlusterCtx } from '../k8sF/ctxF/klusterCtxF.mts'3import { getAction } from '../ctxF/actionCtxF.mts'4import { doSetKlusterWcHnIp } from '../k8sF/genericExtNameSvcF.mts'5import { isDevPc } from '../../sharedF/isDevPcF.mts'6import { getHarvKlustExtIp } from './getHarvKlustExtIpF.mts'7import { pollUntil } from '../../sharedF/sleepF.mts'8import { chalkYellow } from '../../serverF/libChalkF.mts'9import { tryDryRunApply } from '../k8sF/tryDryRunApplyAI.mts'10import type { KubeResource } from '../k8sF/ctxF/klusterCtxF.mts'12export const k8sHarvExtIpSvcs = async (props: Record<string, unknown>) => {13 let {ip} = getKlusterCtx(props)16 ip ||= await getHarvKlustExtIp(props)18 const ips = [ip]20 if (action == 'apply') {21 await fix1IngressPublishAddr({ip: ips[0]})23 if (isDevPc) {24 const {cluster_name} = getKlusterCtx()25 const probeResource = {26 apiVersion: 'v1', kind: 'ConfigMap',27 metadata: {name: 'ingress-recovery-probe', namespace: 'kube-system'},28 data: {probe: 'true'},29 } as KubeResource30 process.stdout.write('waiting for k8s API to stabilize')31 let consecutiveSuccesses = 033 const ok = await tryDryRunApply({resource: probeResource, cluster_name})34 consecutiveSuccesses = ok ? consecutiveSuccesses + 1 : 035 process.stdout.write(ok ? '.' : 'x')36 return consecutiveSuccesses >= 337 }, {timeoutMs: 180_000, intervalMs: 20_000})38 if (recovered) console.log(' ready')39 else console.log(chalkYellow(` not recovered after 3min, continuing anyway`))40 }41 }43 await doSetKlusterWcHnIp({action, ip})44}