mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
refactor: tke ingress 内网配置
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { AbstractTencentPlugin } from '../../tencent/abstract-tencent.js'
|
||||
import tencentcloud from 'tencentcloud-sdk-nodejs'
|
||||
import { K8sClient } from '../../utils/util.k8s.client.js'
|
||||
|
||||
import dns from 'dns'
|
||||
export class DeployCertToTencentTKEIngress extends AbstractTencentPlugin {
|
||||
/**
|
||||
* 插件定义
|
||||
@@ -37,6 +37,10 @@ export class DeployCertToTencentTKEIngress extends AbstractTencentPlugin {
|
||||
label: 'ingress名称',
|
||||
desc: '支持多个(传入数组)'
|
||||
},
|
||||
innerIp: {
|
||||
type: String,
|
||||
label: '集群内网ip'
|
||||
},
|
||||
accessProvider: {
|
||||
label: 'Access提供者',
|
||||
type: [String, Object],
|
||||
@@ -58,6 +62,9 @@ export class DeployCertToTencentTKEIngress extends AbstractTencentPlugin {
|
||||
|
||||
this.logger.info('kubeconfig已成功获取')
|
||||
const k8sClient = new K8sClient(kubeConfigStr)
|
||||
if (props.innerIp != null) {
|
||||
k8sClient.setLookup({ [`${props.clusterId}.ccs.tencent-cloud.com`]: { ip: props.innerIp } })
|
||||
}
|
||||
await this.patchCertSecret({ k8sClient, props, context })
|
||||
await this.sleep(2000) // 停留2秒,等待secret部署完成
|
||||
await this.restartIngress({ k8sClient, props })
|
||||
|
||||
@@ -1,17 +1,45 @@
|
||||
import kubernetesClient from 'kubernetes-client'
|
||||
import { util } from '@certd/api'
|
||||
import Request from 'kubernetes-client/backends/request/index.js'
|
||||
import dns from 'dns'
|
||||
const { KubeConfig, Client } = kubernetesClient
|
||||
const logger = util.logger
|
||||
|
||||
export class K8sClient {
|
||||
constructor (kubeConfigStr) {
|
||||
const kubeconfig = new KubeConfig()
|
||||
kubeconfig.loadFromString(kubeConfigStr)
|
||||
this.kubeConfigStr = kubeConfigStr
|
||||
this.init()
|
||||
}
|
||||
|
||||
const backend = new Request({ kubeconfig })
|
||||
init () {
|
||||
const kubeconfig = new KubeConfig()
|
||||
kubeconfig.loadFromString(this.kubeConfigStr)
|
||||
const reqOpts = { kubeconfig, request: {} }
|
||||
if (this.lookup) {
|
||||
reqOpts.request.lookup = this.lookup
|
||||
}
|
||||
|
||||
const backend = new Request(reqOpts)
|
||||
this.client = new Client({ backend, version: '1.13' })
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param localRecords { [domain]:{ip:'xxx.xx.xxx'} }
|
||||
*/
|
||||
setLookup (localRecords) {
|
||||
this.lookup = (hostnameReq, options, callback) => {
|
||||
logger.info('custom lookup', hostnameReq, localRecords)
|
||||
if (localRecords[hostnameReq]) {
|
||||
logger.info('local record', hostnameReq, localRecords[hostnameReq])
|
||||
callback(null, localRecords[hostnameReq].ip, 4)
|
||||
} else {
|
||||
dns.lookup(hostnameReq, options, callback)
|
||||
}
|
||||
}
|
||||
this.init()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 secret列表
|
||||
* @param opts = {namespace:default}
|
||||
|
||||
Reference in New Issue
Block a user