🌳
pt0/deployF/k8sF/fix1IngressPublishAddrAI.mts
3import { getKlusterCtx, type KubeResource } from './ctxF/klusterCtxF.mts'
4import * as _ from 'lodash-es'
6export const fix1IngressPublishAddr = async ({ip}: {ip: string}) => {
7 const {cluster_name} = getKlusterCtx()
8 const kinds = ['Deployment', 'DaemonSet'] as const
9 const candidates = [
10 {name: 'ingress-nginx-controller', namespace: 'ingress-nginx'},
11 {name: 'rke2-ingress-nginx-controller', namespace: 'kube-system'},
12 ]
14 for (const {name, namespace} of candidates) {
15 for (const kind of kinds) {
16 const resource: any = await read2Resource({
17 cluster_name,
18 resource: {
19 apiVersion: 'apps/v1',
20 kind,
21 metadata: {name, namespace},
22 },
23 })
24 if (!resource) continue
26 const container = resource.spec.template.spec.containers[0]
27 const newArg = `--publish-status-address=${ip}`
28 const argI = _.findIndex(container.args, (argS: string) => _.startsWith(argS, '--publish-status-address'))
30 if (argI !== -1 && container.args[argI] === newArg) {
31 console.log(`fix1IngressPublishAddr: ${name} already set to ${ip}`)
32 return
33 }
35 if (argI === -1) {
36 container.args.push(newArg)
37 console.log(`fix1IngressPublishAddr: adding ${newArg} to ${name}`)
38 } else {
39 const oldArg = container.args[argI]
40 container.args[argI] = newArg
41 console.log(`fix1IngressPublishAddr: ${name} ${oldArg} -> ${newArg}`)
42 }
44 await res1Action({action: 'apply', resource: resource as KubeResource, cluster_name})
45 return
46 }
47 }
49 console.log('fix1IngressPublishAddr: ingress controller not found')