Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redis and dyminic dbversion (#3449)
* get version by cr * feat: redis
- Loading branch information
Showing
18 changed files
with
392 additions
and
60 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
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,4 +1,6 @@ | ||
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'; | ||
|
||
export const getResourcePrice = () => GET<resourcePriceResponse>('/api/platform/resourcePrice'); | ||
export const getDBVersionMap = () => GET<DBVersionMapType>('/api/platform/getVersion'); |
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
64 changes: 64 additions & 0 deletions
64
frontend/providers/dbprovider/src/pages/api/platform/getVersion.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,64 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { K8sApi } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
import { DBTypeEnum } from '@/constants/db'; | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
export type Response = Record< | ||
`${DBTypeEnum}`, | ||
{ | ||
id: string; | ||
label: string; | ||
}[] | ||
>; | ||
|
||
const MOCK = { | ||
[DBTypeEnum.postgresql]: [{ id: 'postgresql-14.8.0', label: 'postgresql-14.8.0' }], | ||
[DBTypeEnum.mongodb]: [{ id: 'mongodb-5.0.14', label: 'mongodb-5.0.14' }], | ||
[DBTypeEnum.mysql]: [{ id: 'ac-mysql-8.0.30', label: 'ac-mysql-8.0.30' }], | ||
[DBTypeEnum.redis]: [{ id: 'redis-7.0.6', label: 'redis-7.0.6' }] | ||
}; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
try { | ||
const DBVersionMap: Response = { | ||
[DBTypeEnum.postgresql]: [], | ||
[DBTypeEnum.mongodb]: [], | ||
[DBTypeEnum.mysql]: [], | ||
[DBTypeEnum.redis]: [] | ||
}; | ||
|
||
// source price | ||
const kc = K8sApi(); | ||
const k8sCustomObjects = kc.makeApiClient(k8s.CustomObjectsApi); | ||
|
||
const { body } = (await k8sCustomObjects.listClusterCustomObject( | ||
'apps.kubeblocks.io', | ||
'v1alpha1', | ||
'clusterversions' | ||
)) as any; | ||
|
||
body.items.forEach((item: any) => { | ||
const db = item?.spec?.clusterDefinitionRef as `${DBTypeEnum}`; | ||
if ( | ||
DBVersionMap[db] && | ||
item?.metadata?.name && | ||
!DBVersionMap[db].find((db) => db.id === item.metadata.name) | ||
) { | ||
DBVersionMap[db].push({ | ||
id: item.metadata.name, | ||
label: item.metadata.name | ||
}); | ||
} | ||
}); | ||
|
||
jsonRes(res, { | ||
data: DBVersionMap | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
jsonRes(res, { | ||
data: MOCK | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.