Skip to content

Commit

Permalink
fix: adjust GPU quota for launchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
zjy365 committed Sep 5, 2024
1 parent 9ca435c commit 6996b77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {
Expand Down Expand Up @@ -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 {
Expand All @@ -84,7 +87,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
quota: UserQuotaItemType[];
}>(res, {
data: {
quota,
quota: filteredQuota,
balance
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,21 @@ const Form = ({
key={item.value}
label={hasInventory ? '' : t('Under Stock')}
>
<Box
<Center
mr={2}
w={'32px'}
h={'32px'}
lineHeight={'32px'}
textAlign={'center'}
borderRadius={'md'}
border={'1px solid'}
bg={'myWhite.500'}
bg={'white'}
{...(getValues('gpu.amount') === item.value
? {
borderColor: 'brightBlue.600',
boxShadow: '0px 0px 4px #A8DBFF'
borderColor: 'brightBlue.500',
boxShadow: '0px 0px 0px 2.4px rgba(33, 155, 244, 0.15)'
}
: {
borderColor: 'myGray.200'
borderColor: 'grayModern.200',
bgColor: 'grayModern.100'
})}
{...(hasInventory
? {
Expand All @@ -703,7 +702,7 @@ const Form = ({
})}
>
{item.label}
</Box>
</Center>
</MyTooltip>
);
})}
Expand Down

0 comments on commit 6996b77

Please sign in to comment.