diff --git a/src/index.ts b/src/index.ts index 2f5c8c4..d97c4a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,7 +52,7 @@ program.command('serve').action(async () => { await worker.startForK8s(); } } catch (err) { - log.error(`[-] Failed to start Worker - ${err.message}`); + log.error(`[-] Failed to start Worker - ${JSON.stringify(err)}`); } }); diff --git a/src/manager/worker.ts b/src/manager/worker.ts index 3543da9..a5b0174 100644 --- a/src/manager/worker.ts +++ b/src/manager/worker.ts @@ -650,10 +650,10 @@ export default class WorkerBase { /** * It is CallBack Function for Watching Pod Information [UPDATE, ADDED]. */ - protected podUpdataOrAddCallback = async (data: types.PodInfo) => { + protected podUpdateOrAddCallback = async (data: types.PodInfo) => { try { if (data.labels && data.labels.ainConnect) { - log.debug(`[+] podUpdataOrAddCallback podName: ${data.appName}, status:${data.status.phase}`); + log.debug(`[+] podUpdateOrAddCallback podName: ${data.appName}, status:${data.status.phase}`); await this.writePodStatus(data); } } catch (err) { @@ -665,20 +665,28 @@ export default class WorkerBase { * It is CallBack Function for Watching Pod Information [DELETE]. */ protected podDeleteCallback = async (data: types.PodInfo) => { - log.debug(`[+] podDeleteCallback podName: ${data.appName}, status:${data.status}`); + log.debug(`[+] podDeleteCallback podName: ${data.appName}, status:${data.status.phase}`); // Only information generated through API is removed in redis. if (data.labels && data.labels.ainConnect) { if (data.labels && data.labels.nfs) { - await this.connectSdk.deleteStorageStatus( - this.workerInfo.clusterName, data.appName, - ); + try { + await this.connectSdk.deleteStorageStatus( + this.workerInfo.clusterName, data.appName, + ); + } catch (err) { + log.error(`[-] Failed to delete Storage ${err.message}`); + } } else { - await this.connectSdk.deletePodStatus( - this.workerInfo.clusterName, data.appName, - data.name, - ); - if (this.connectContainerInfo && this.connectContainerInfo[data.appName][data.name]) { - delete this.connectContainerInfo[data.appName][data.name]; + try { + await this.connectSdk.deletePodStatus( + this.workerInfo.clusterName, data.appName, + data.name, + ); + if (this.connectContainerInfo && this.connectContainerInfo[data.appName][data.name]) { + delete this.connectContainerInfo[data.appName][data.name]; + } + } catch (err) { + log.error(`[-] Failed to delete NodeInfo ${err.message}`); } } } @@ -689,11 +697,11 @@ export default class WorkerBase { */ protected watchPodInfos() { this.k8sApi.makeInformerPod( - this.podUpdataOrAddCallback, // ADDED - this.podUpdataOrAddCallback, // UPDATE + this.podUpdateOrAddCallback, // ADDED + this.podUpdateOrAddCallback, // UPDATE this.podDeleteCallback, // DELETE async () => { // ERROR - log.debug('[+] watchPodInfos Error'); + log.error('[-] watchPodInfos Error'); // Remove Pod Information on Redis for sync. await this.initPodInfo(); }, diff --git a/src/util/k8s/api.ts b/src/util/k8s/api.ts index d715036..ed3557e 100644 --- a/src/util/k8s/api.ts +++ b/src/util/k8s/api.ts @@ -4,6 +4,9 @@ import * as request from 'request'; import * as http2 from 'http2'; import * as util from 'util'; import * as types from '../../common/types'; +import Logger from '../../common/logger'; + +const log = Logger.createLogger('util.k8s.api'); const exec = util.promisify(require('child_process').exec); @@ -754,6 +757,10 @@ export default class Api { const url = new URL(opts.uri); const host = `${url.protocol}//${url.host}`; const http2ClientSession = http2.connect(host, { ca: connectionOptions['ca'] }); + http2ClientSession.on('error', (error) => { + log.error(`[-] http2ClientSession error - ${JSON.stringify(error)}`); + }); + let path = '/api/v1/pods?watch=true'; if (opts && opts.qs && opts.qs.resourceVersion) { path += `&resourceVersion=${opts.qs.resourceVersion}`; @@ -786,6 +793,7 @@ export default class Api { }, 5000); http2Stream.on('end', () => { + log.info('[+] http2Stream ended'); clearInterval(pingInterval); http2ClientSession.close(); this.informer.off('error', errorHandler); @@ -794,6 +802,10 @@ export default class Api { this.informer.off('delete', deleteHandler); this.informer.stop(); }); + + http2Stream.on('error', (error) => { + log.error(`[-] http2Stream error - ${JSON.stringify(error)}`); + }); return http2Stream; }, };