From efacfd6b2c477e84ece32dcb41a268cab4012740 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 6 Aug 2024 10:22:28 +0800 Subject: [PATCH] chore: k8s logger --- packages/libs/lib-k8s/src/lib/k8s.client.ts | 12 +++++++----- .../plugin/deploy-to-ack-ingress/index.ts | 2 +- .../src/plugins/plugin-demo/plugins/plugin-test.ts | 2 +- .../plugin/deploy-to-tke-ingress/index.ts | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/libs/lib-k8s/src/lib/k8s.client.ts b/packages/libs/lib-k8s/src/lib/k8s.client.ts index 4d40d2b8..cc909e9d 100644 --- a/packages/libs/lib-k8s/src/lib/k8s.client.ts +++ b/packages/libs/lib-k8s/src/lib/k8s.client.ts @@ -1,7 +1,7 @@ import kubernetesClient from 'kubernetes-client'; //@ts-ignore import dns from 'dns'; -import { logger } from '@certd/pipeline'; +import { ILogger } from '@certd/pipeline'; //@ts-ignore const { KubeConfig, Client, Request } = kubernetesClient; @@ -10,8 +10,10 @@ export class K8sClient { kubeConfigStr: string; lookup!: any; client!: any; - constructor(kubeConfigStr: string) { + logger: ILogger; + constructor(kubeConfigStr: string, logger: ILogger) { this.kubeConfigStr = kubeConfigStr; + this.logger = logger; this.init(); } @@ -33,9 +35,9 @@ export class K8sClient { */ setLookup(localRecords: { [key: string]: { ip: string } }) { this.lookup = (hostnameReq: any, options: any, callback: any) => { - logger.info('custom lookup', hostnameReq, localRecords); + this.logger.info('custom lookup', hostnameReq, localRecords); if (localRecords[hostnameReq]) { - logger.info('local record', hostnameReq, localRecords[hostnameReq]); + this.logger.info('local record', hostnameReq, localRecords[hostnameReq]); callback(null, localRecords[hostnameReq].ip, 4); } else { dns.lookup(hostnameReq, options, callback); @@ -64,7 +66,7 @@ export class K8sClient { const created = await this.client.api.v1.namespaces(namespace).secrets.post({ body: opts.body, }); - logger.info('new secrets:', created); + this.logger.info('new secrets:', created); return created; } diff --git a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-ack-ingress/index.ts b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-ack-ingress/index.ts index 479ef6d9..b0280019 100644 --- a/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-ack-ingress/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/plugin/deploy-to-ack-ingress/index.ts @@ -121,7 +121,7 @@ export class DeployCertToAliyunAckIngressPlugin extends AbstractTaskPlugin { const kubeConfigStr = await this.getKubeConfig(client, clusterId, isPrivateIpAddress); this.logger.info('kubeconfig已成功获取'); - const k8sClient = new K8sClient(kubeConfigStr); + const k8sClient = new K8sClient(kubeConfigStr,this.logger); const ingressType = ingressClass || 'qcloud'; if (ingressType === 'qcloud') { throw new Error('暂未实现'); diff --git a/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts b/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts index 55955303..811a6e80 100644 --- a/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts +++ b/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts @@ -91,7 +91,7 @@ export class DemoTestPlugin extends AbstractTaskPlugin { this.logger.info('授权id:', accessId); //TODO 这里实现你要部署的执行方法 - new K8sClient('111'); + new K8sClient('111', logger); } } //TODO 这里实例化插件,进行注册 diff --git a/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-tke-ingress/index.ts b/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-tke-ingress/index.ts index aa212c93..34aa5b7c 100644 --- a/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-tke-ingress/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/deploy-to-tke-ingress/index.ts @@ -101,7 +101,7 @@ export class DeployCertToTencentTKEIngressPlugin extends AbstractTaskPlugin { const kubeConfigStr = await this.getTkeKubeConfig(tkeClient, this.clusterId); this.logger.info('kubeconfig已成功获取'); - const k8sClient = new K8sClient(kubeConfigStr); + const k8sClient = new K8sClient(kubeConfigStr, this.logger); if (this.clusterIp != null) { if (!this.clusterDomain) { this.clusterDomain = `${this.clusterId}.ccs.tencent-cloud.com`;