Skip to content

Commit 5db9ff8

Browse files
committed
fix: ip 할당되지 않은 경우 다시 ip 조회
1 parent 8d39cb1 commit 5db9ff8

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

DBManager/src/k8s/K8SApi.service.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ export class K8SApiService {
2626

2727
startWatchPod() {
2828
const path = `/api/v1/namespaces/${this.namespace}/pods`;
29-
const queryParams = { allowWatchBookmarks: true };
29+
const queryParams = {
30+
allowWatchBookmarks: true,
31+
labelSelector: 'app=mysql',
32+
};
3033
const handlePodEvent = async (type : String, apiObj: any, watchObj: any) => {
31-
if (type === 'ADDED') {
32-
const createdPod = watchObj.object.metadata.name;
33-
const podIp = await this.getPodIp(createdPod);
34+
const podName = watchObj.object.metadata.name;
35+
const podStatus = watchObj.object.status;
36+
const curPodIp = await this.redisService.hgetPod(podName, 'podIp');
3437

35-
await this.redisService.hsetPod(createdPod, 'activeUser', 0);
36-
//TODO ip가 바로 생성되지 않는 문제 해결 필요
37-
await this.redisService.hsetPod(createdPod, 'podIp', podIp);
38+
if (type === 'ADDED') {
39+
await this.redisService.hsetPod(podName, 'activeUser', 0);
40+
await this.redisService.hsetPod(podName, 'podIp', podStatus.podIp || '');
41+
} else if (type === 'MODIFIED' && podStatus.podIP && curPodIp == '') {
42+
const podIp = podStatus.podIP;
43+
await this.redisService.hsetPod(podName, 'podIp', podIp);
3844
} else if (type === 'DELETED') {
39-
const deletedPod = watchObj.object.metadata.name;
40-
await this.redisService.delPod(deletedPod);
45+
await this.redisService.delPod(podName);
4146
}
4247
};
4348

@@ -50,6 +55,9 @@ export class K8SApiService {
5055
const mysqlPod = {
5156
metadata: {
5257
name: podName,
58+
labels: {
59+
app: 'mysql',
60+
},
5361
},
5462
spec: {
5563
containers: [

0 commit comments

Comments
 (0)