forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPodsByDBName.ts
43 lines (38 loc) · 1.09 KB
/
getPodsByDBName.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { NextApiRequest, NextApiResponse } from 'next';
import { ApiResp } from '@/services/kubernet';
import { authSession } from '@/services/backend/auth';
import { getK8s } from '@/services/backend/kubernetes';
import { jsonRes } from '@/services/backend/response';
import { KBBackupNameLabel } from '@/constants/db';
// get App Metrics By DeployName. compute average value
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
const { name } = req.query;
if (!name) {
throw new Error('Name is empty');
}
const { k8sCore, namespace } = await getK8s({
kubeconfig: await authSession(req)
});
// get pods
const {
body: { items: pods }
} = await k8sCore.listNamespacedPod(
namespace,
undefined,
undefined,
undefined,
undefined,
`app.kubernetes.io/instance=${name},!${KBBackupNameLabel}`
);
jsonRes(res, {
data: pods
});
} catch (err: any) {
// console.log(err, 'get metrics error')
jsonRes(res, {
code: 500,
error: err
});
}
}