From 6996b778c997abd2e32fd355612ae1787a72aa12 Mon Sep 17 00:00:00 2001 From: zjy <3161362058@qq.com> Date: Thu, 5 Sep 2024 14:54:06 +0800 Subject: [PATCH] fix: adjust GPU quota for launchpad --- .../src/pages/api/platform/getQuota.ts | 7 +++++-- .../src/pages/api/platform/resourcePrice.ts | 2 +- .../src/pages/app/edit/components/Form.tsx | 15 +++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/providers/applaunchpad/src/pages/api/platform/getQuota.ts b/frontend/providers/applaunchpad/src/pages/api/platform/getQuota.ts index 4e0f1f9fc7a..2cdafe2cb0d 100644 --- a/frontend/providers/applaunchpad/src/pages/api/platform/getQuota.ts +++ b/frontend/providers/applaunchpad/src/pages/api/platform/getQuota.ts @@ -4,6 +4,7 @@ import { jsonRes } from '@/services/backend/response'; import { authSession } from '@/services/backend/auth'; import { UserQuotaItemType } from '@/types/user'; import Decimal from 'decimal.js'; +import { getGpuNode } from './resourcePrice'; async function getAmount(req: NextApiRequest): Promise<{ data?: { @@ -60,11 +61,13 @@ async function getAmount(req: NextApiRequest): Promise<{ export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { // source price - const { getUserQuota } = await getK8s({ + const { getUserQuota, k8sCore } = await getK8s({ kubeconfig: await authSession(req.headers) }); const quota = await getUserQuota(); + const gpuNodes = await getGpuNode({ k8sCore }); + const filteredQuota = gpuNodes.length > 0 ? quota : quota.filter((item) => item.type !== 'gpu'); let balance = '0'; try { @@ -84,7 +87,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) quota: UserQuotaItemType[]; }>(res, { data: { - quota, + quota: filteredQuota, balance } }); diff --git a/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts b/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts index 5bc61d3751c..64177d53e08 100644 --- a/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts +++ b/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts @@ -75,7 +75,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } /* get gpu nodes by configmap. */ -async function getGpuNode({ k8sCore }: { k8sCore: CoreV1Api }) { +export async function getGpuNode({ k8sCore }: { k8sCore: CoreV1Api }) { try { const { body } = await k8sCore.readNamespacedConfigMap(gpuCrName, gpuCrNS); const gpuMap = body?.data?.gpu; diff --git a/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx b/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx index 843871bc4b7..d0597e85396 100644 --- a/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx +++ b/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx @@ -670,22 +670,21 @@ const Form = ({ key={item.value} label={hasInventory ? '' : t('Under Stock')} > - {item.label} - + ); })}