mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
chore: k8s logger
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import kubernetesClient from 'kubernetes-client';
|
import kubernetesClient from 'kubernetes-client';
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import dns from 'dns';
|
import dns from 'dns';
|
||||||
import { logger } from '@certd/pipeline';
|
import { ILogger } from '@certd/pipeline';
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const { KubeConfig, Client, Request } = kubernetesClient;
|
const { KubeConfig, Client, Request } = kubernetesClient;
|
||||||
@@ -10,8 +10,10 @@ export class K8sClient {
|
|||||||
kubeConfigStr: string;
|
kubeConfigStr: string;
|
||||||
lookup!: any;
|
lookup!: any;
|
||||||
client!: any;
|
client!: any;
|
||||||
constructor(kubeConfigStr: string) {
|
logger: ILogger;
|
||||||
|
constructor(kubeConfigStr: string, logger: ILogger) {
|
||||||
this.kubeConfigStr = kubeConfigStr;
|
this.kubeConfigStr = kubeConfigStr;
|
||||||
|
this.logger = logger;
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,9 +35,9 @@ export class K8sClient {
|
|||||||
*/
|
*/
|
||||||
setLookup(localRecords: { [key: string]: { ip: string } }) {
|
setLookup(localRecords: { [key: string]: { ip: string } }) {
|
||||||
this.lookup = (hostnameReq: any, options: any, callback: any) => {
|
this.lookup = (hostnameReq: any, options: any, callback: any) => {
|
||||||
logger.info('custom lookup', hostnameReq, localRecords);
|
this.logger.info('custom lookup', hostnameReq, localRecords);
|
||||||
if (localRecords[hostnameReq]) {
|
if (localRecords[hostnameReq]) {
|
||||||
logger.info('local record', hostnameReq, localRecords[hostnameReq]);
|
this.logger.info('local record', hostnameReq, localRecords[hostnameReq]);
|
||||||
callback(null, localRecords[hostnameReq].ip, 4);
|
callback(null, localRecords[hostnameReq].ip, 4);
|
||||||
} else {
|
} else {
|
||||||
dns.lookup(hostnameReq, options, callback);
|
dns.lookup(hostnameReq, options, callback);
|
||||||
@@ -64,7 +66,7 @@ export class K8sClient {
|
|||||||
const created = await this.client.api.v1.namespaces(namespace).secrets.post({
|
const created = await this.client.api.v1.namespaces(namespace).secrets.post({
|
||||||
body: opts.body,
|
body: opts.body,
|
||||||
});
|
});
|
||||||
logger.info('new secrets:', created);
|
this.logger.info('new secrets:', created);
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -121,7 +121,7 @@ export class DeployCertToAliyunAckIngressPlugin extends AbstractTaskPlugin {
|
|||||||
const kubeConfigStr = await this.getKubeConfig(client, clusterId, isPrivateIpAddress);
|
const kubeConfigStr = await this.getKubeConfig(client, clusterId, isPrivateIpAddress);
|
||||||
|
|
||||||
this.logger.info('kubeconfig已成功获取');
|
this.logger.info('kubeconfig已成功获取');
|
||||||
const k8sClient = new K8sClient(kubeConfigStr);
|
const k8sClient = new K8sClient(kubeConfigStr,this.logger);
|
||||||
const ingressType = ingressClass || 'qcloud';
|
const ingressType = ingressClass || 'qcloud';
|
||||||
if (ingressType === 'qcloud') {
|
if (ingressType === 'qcloud') {
|
||||||
throw new Error('暂未实现');
|
throw new Error('暂未实现');
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class DemoTestPlugin extends AbstractTaskPlugin {
|
|||||||
this.logger.info('授权id:', accessId);
|
this.logger.info('授权id:', accessId);
|
||||||
//TODO 这里实现你要部署的执行方法
|
//TODO 这里实现你要部署的执行方法
|
||||||
|
|
||||||
new K8sClient('111');
|
new K8sClient('111', logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO 这里实例化插件,进行注册
|
//TODO 这里实例化插件,进行注册
|
||||||
|
|||||||
+1
-1
@@ -101,7 +101,7 @@ export class DeployCertToTencentTKEIngressPlugin extends AbstractTaskPlugin {
|
|||||||
const kubeConfigStr = await this.getTkeKubeConfig(tkeClient, this.clusterId);
|
const kubeConfigStr = await this.getTkeKubeConfig(tkeClient, this.clusterId);
|
||||||
|
|
||||||
this.logger.info('kubeconfig已成功获取');
|
this.logger.info('kubeconfig已成功获取');
|
||||||
const k8sClient = new K8sClient(kubeConfigStr);
|
const k8sClient = new K8sClient(kubeConfigStr, this.logger);
|
||||||
if (this.clusterIp != null) {
|
if (this.clusterIp != null) {
|
||||||
if (!this.clusterDomain) {
|
if (!this.clusterDomain) {
|
||||||
this.clusterDomain = `${this.clusterId}.ccs.tencent-cloud.com`;
|
this.clusterDomain = `${this.clusterId}.ccs.tencent-cloud.com`;
|
||||||
|
|||||||
Reference in New Issue
Block a user