Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/seonghwa/new error logs #9

Open
wants to merge 2 commits into
base: feature/donghyeon/kubectl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
});

Expand Down
38 changes: 23 additions & 15 deletions src/manager/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}`);
}
}
}
Expand All @@ -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();
},
Expand Down
12 changes: 12 additions & 0 deletions src/util/k8s/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
},
};
Expand Down