-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat:db add quota Signed-off-by: jingyang <[email protected]> * add cronjob key Signed-off-by: jingyang <[email protected]> --------- Signed-off-by: jingyang <[email protected]>
- Loading branch information
Showing
21 changed files
with
387 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// applanuchpad | ||
export const pauseKey = 'deploy.cloud.sealos.io/pause'; | ||
export const deployManagerKey = 'cloud.sealos.io/app-deploy-manager'; | ||
export const noGpuSliderKey = 'NoGpu'; | ||
export const maxReplicasKey = 'deploy.cloud.sealos.io/maxReplicas'; | ||
export const minReplicasKey = 'deploy.cloud.sealos.io/minReplicas'; | ||
export const appDeployKey = 'cloud.sealos.io/app-deploy-manager'; | ||
export const publicDomainKey = `cloud.sealos.io/app-deploy-manager-domain`; | ||
export const gpuNodeSelectorKey = 'nvidia.com/gpu.product'; | ||
export const gpuResourceKey = 'nvidia.com/gpu'; | ||
// template | ||
export const templateDeployKey = 'cloud.sealos.io/deploy-on-sealos'; | ||
// db | ||
export const kubeblocksTypeKey = 'clusterdefinition.kubeblocks.io/name'; | ||
// labels | ||
export const componentLabel = 'app.kubernetes.io/component'; | ||
// cronjob | ||
export const cronJobTypeKey = 'cronjob-type'; | ||
export const cronJobKey = 'cloud.sealos.io/cronjob'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { GET, POST, DELETE } from '@/services/request'; | ||
import type { Response as resourcePriceResponse } from '@/pages/api/platform/resourcePrice'; | ||
import type { Response as DBVersionMapType } from '@/pages/api/platform/getVersion'; | ||
import { Response as EnvResponse } from '@/pages/api/getEnv'; | ||
import type { Response as DBVersionMapType } from '@/pages/api/platform/getVersion'; | ||
import type { Response as resourcePriceResponse } from '@/pages/api/platform/resourcePrice'; | ||
import { GET } from '@/services/request'; | ||
import type { UserQuotaItemType } from '@/types/user'; | ||
|
||
export const getResourcePrice = () => GET<resourcePriceResponse>('/api/platform/resourcePrice'); | ||
export const getAppEnv = () => GET<EnvResponse>('/api/getEnv'); | ||
export const getDBVersionMap = () => GET<DBVersionMapType>('/api/platform/getVersion'); | ||
|
||
export const getUserQuota = () => | ||
GET<{ | ||
balance: number; | ||
quota: UserQuotaItemType[]; | ||
}>('/api/platform/getQuota'); |
24 changes: 24 additions & 0 deletions
24
frontend/providers/dbprovider/src/pages/api/platform/getQuota.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { getK8s } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
import { authSession } from '@/services/backend/auth'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
try { | ||
// source price | ||
const { getUserQuota, getUserBalance } = await getK8s({ | ||
kubeconfig: await authSession(req) | ||
}); | ||
|
||
const [quota, balance] = await Promise.all([getUserQuota(), getUserBalance()]); | ||
|
||
jsonRes(res, { | ||
data: { | ||
quota, | ||
balance | ||
} | ||
}); | ||
} catch (error) { | ||
jsonRes(res, { code: 500, message: 'get price error' }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
frontend/providers/dbprovider/src/pages/db/edit/components/QuotaBox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Box, Flex, useTheme, Progress, css } from '@chakra-ui/react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useTranslation } from 'next-i18next'; | ||
import MyTooltip from '@/components/MyTooltip'; | ||
import { useUserStore } from '@/store/user'; | ||
|
||
const sourceMap = { | ||
cpu: { | ||
color: '#33BABB', | ||
unit: 'Core' | ||
}, | ||
memory: { | ||
color: '#36ADEF', | ||
unit: 'Gi' | ||
}, | ||
storage: { | ||
color: '#8172D8', | ||
unit: 'GB' | ||
}, | ||
gpu: { | ||
color: '#89CD11', | ||
unit: 'Card' | ||
} | ||
}; | ||
|
||
const QuotaBox = () => { | ||
const theme = useTheme(); | ||
const { t } = useTranslation(); | ||
const { userQuota, loadUserQuota } = useUserStore(); | ||
useQuery(['getUserQuota'], loadUserQuota); | ||
|
||
const quotaList = useMemo(() => { | ||
if (!userQuota) return []; | ||
return userQuota | ||
.map((item) => ({ | ||
...item, | ||
tip: `${t('Total')}: ${`${item.limit} ${sourceMap[item.type]?.unit}`} | ||
${t('common.Used')}: ${`${item.used} ${sourceMap[item.type]?.unit}`} | ||
${t('common.Surplus')}: ${`${item.limit - item.used} ${sourceMap[item.type]?.unit}`} | ||
`, | ||
color: sourceMap[item.type]?.color | ||
})) | ||
.filter((item) => item.limit > 0); | ||
}, [userQuota, t]); | ||
|
||
return userQuota.length === 0 ? null : ( | ||
<Box> | ||
<Box py={3} px={4} borderBottom={theme.borders.base}> | ||
<strong>{t('app.Resource Quota')}</strong> | ||
</Box> | ||
<Box py={3} px={4}> | ||
{quotaList.map((item) => ( | ||
<MyTooltip key={item.type} label={item.tip} placement={'top-end'} lineHeight={1.7}> | ||
<Flex alignItems={'center'} _notFirst={{ mt: 3 }}> | ||
<Box flex={'0 0 60px'}>{t(item.type)}</Box> | ||
<Progress | ||
flex={'1 0 0'} | ||
borderRadius={'sm'} | ||
size="sm" | ||
value={item.used} | ||
max={item.limit} | ||
css={css({ | ||
'& > div': { | ||
bg: item.color | ||
} | ||
})} | ||
/> | ||
</Flex> | ||
</MyTooltip> | ||
))} | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default QuotaBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.