refactor: tke ingress 内网配置

This commit is contained in:
xiaojunnuo
2021-01-08 13:01:35 +08:00
parent bd00c09da0
commit ce5aae3795
4 changed files with 242 additions and 18 deletions
@@ -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 })
+31 -3
View File
@@ -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}