🌳
pt0/deployF/harvF/harvExtIpsSyncF/mkjob.mts
11import type { HarvKlusterCfg } from '../harvSetupCtxF.mts'
14const runFilePath = ptAnchorInclude('./run.mts', import.meta.url)
16export const k8sHarvExtIp = async () => {
17 const kcfg = getReqKlusterCtx() as HarvKlusterCfg & {dockLanHost?: string, nodeIpsExtHost?: string}
18 const {accessByIp, klusterVipHostname, clusterVip, klustCertsH, k8sCloudName, dockLanHost, nodeIpsExtHost, cluster_name, cfApiKeySecretName, domainNames} = kcfg
19 const useLocalDocker = k8sCloudName === 'harvester'
20 // LAN registry only when the dev PC is actually on this cluster's LAN; otherwise the external dockreg (reachable from any network — avoids a cluster's internal hostname being used from another network)
21 const onLan = useLocalDocker && !!dockLanHost && await isOnSameLan({cluster_name, nodeIpsExtHost, clusterVip})
22 const dockreg_host_override = onLan ? dockLanHost : undefined
23 if (dockreg_host_override) {
24 betLog(`k8sHarvExtIp: using docker + LAN registry ${dockreg_host_override}`)
25 process.stdout.write('waiting for docker registry')
26 const recovered = await pollUntil(async () => {
27 const resp = await fetch(`https://${dockreg_host_override}/v2/`).catch(() => null)
28 const ok = resp?.status === 200 || resp?.status === 401
29 process.stdout.write(ok ? '.' : 'x')
30 return ok
31 }, {timeoutMs: 120_000, intervalMs: 5_000})
32 if (recovered) console.log(' ready')
33 else console.log(chalkYellow(' not available after 2min, continuing anyway'))
34 } else if (useLocalDocker && dockLanHost) {
35 betLog({k8sHarvExtIp: 'off-LAN, using external dockreg'})
36 }
37 const run = async () => eptMjsRunner({
38 ...kcfg,
39 ...(dockreg_host_override && {dockreg_host: dockreg_host_override}),
40 importMetaUrl: tsImportMetaUrl(import.meta.url),
41 runFilePath,
42 name: 'harvextipsync',
43 appPath: 'pt0/deployF',
44 bundle: true,
45 envConf: {accessByIp, klusterVipHostname, clusterVip, klustCertsH, cfApiKeySecretName, domainNames},
46 extraDockerSetupLine: 'RUN curl -LO "https://dl.k8s.io/release/v1.35.2/bin/linux/amd64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin/',
47 jobType: {
48 kind: 'CronJob',
49 schedule: '*/5 * * * *',
50 ...syncCronJobPolicy,
51 },
52 secretNames: [
53 getKubeConfigFilename(kcfg.cluster_name),
54 ...(cfApiKeySecretName ? [cfApiKeySecretName] : []),
55 ],
56 })
57 if (useLocalDocker) await dockBuildCtx.run({dockName: 'docker'}, run)
58 else await run()