From fe50d0986028ac1e78b174c8ac0133ea5874b8a7 Mon Sep 17 00:00:00 2001 From: zhujingyang <72259332+zjy365@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:00:19 +0800 Subject: [PATCH] fix:dbprovider number of database instances (#4580) * fix:dbprovider number of database instances Signed-off-by: jingyang <3161362058@qq.com> * fix db secret Signed-off-by: jingyang <3161362058@qq.com> --------- Signed-off-by: jingyang <3161362058@qq.com> --- .../dbprovider/public/locales/en/common.json | 5 ++-- .../dbprovider/public/locales/zh/common.json | 5 ++-- .../src/pages/api/getSecretByName.ts | 6 ++--- .../src/pages/db/edit/components/Form.tsx | 23 +++++++++--------- .../dbprovider/src/utils/json2Yaml.ts | 24 ++++++++++++++++--- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/frontend/providers/dbprovider/public/locales/en/common.json b/frontend/providers/dbprovider/public/locales/en/common.json index 0837970773a..db5bc411efe 100644 --- a/frontend/providers/dbprovider/public/locales/en/common.json +++ b/frontend/providers/dbprovider/public/locales/en/common.json @@ -262,5 +262,6 @@ "db instances tip": "The number of {{db}} instances is recommended to be an odd number", "Deleting": "Deleting", "Backup Running": "Backup Running", - "Backup Deleting": "Backup Deleting" -} \ No newline at end of file + "Backup Deleting": "Backup Deleting", + "DataBase": "DataBase" +} diff --git a/frontend/providers/dbprovider/public/locales/zh/common.json b/frontend/providers/dbprovider/public/locales/zh/common.json index 25d0c9b4146..ba9427d44f7 100644 --- a/frontend/providers/dbprovider/public/locales/zh/common.json +++ b/frontend/providers/dbprovider/public/locales/zh/common.json @@ -265,5 +265,6 @@ "db instances tip": "{{db}} 实例数量建议为奇数", "Deleting": "删除中", "Backup Running": "备份中", - "Backup Deleting": "删除中" -} \ No newline at end of file + "Backup Deleting": "删除中", + "DataBase": "数据库" +} diff --git a/frontend/providers/dbprovider/src/pages/api/getSecretByName.ts b/frontend/providers/dbprovider/src/pages/api/getSecretByName.ts index df52c58f01c..40e090e1e52 100644 --- a/frontend/providers/dbprovider/src/pages/api/getSecretByName.ts +++ b/frontend/providers/dbprovider/src/pages/api/getSecretByName.ts @@ -94,9 +94,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< 'base64' ).toString('utf-8'); - const host = Buffer.from(secret.body.data[dbTypeMap[dbType].hostKey], 'base64').toString( - 'utf-8' - ); + const host = + Buffer.from(secret.body.data[dbTypeMap[dbType].hostKey], 'base64').toString('utf-8') + + `.${namespace}.svc`; const port = Buffer.from(secret.body.data[dbTypeMap[dbType].portKey], 'base64').toString( 'utf-8' diff --git a/frontend/providers/dbprovider/src/pages/db/edit/components/Form.tsx b/frontend/providers/dbprovider/src/pages/db/edit/components/Form.tsx index da841b46dca..0377907f990 100644 --- a/frontend/providers/dbprovider/src/pages/db/edit/components/Form.tsx +++ b/frontend/providers/dbprovider/src/pages/db/edit/components/Form.tsx @@ -173,17 +173,6 @@ const Form = ({ fontWeight: 'bold', borderColor: 'myGray.900' }} - // {...(activeNav === item.id - // ? { - // fontWeight: 'bold', - // borderColor: 'myGray.900', - // backgroundColor: 'myWhite.600 !important' - // } - // : { - // color: 'myGray.500', - // borderColor: 'myGray.200', - // backgroundColor: 'transparent' - // })} > { register('replicas', { required: t('Replicas Cannot Empty') || '', @@ -329,7 +324,11 @@ const Form = ({ message: `${t('Max Replicas')}20` } }); - setValue('replicas', val || 1); + const dbType = getValues('dbType'); + const oddVal = val % 2 === 0 ? val + 1 : val; + const replicasValue = + dbType === DBTypeEnum.mongodb || dbType === DBTypeEnum.mysql ? oddVal : val; + setValue('replicas', isNaN(replicasValue) ? 1 : replicasValue); }} /> {getValues('replicas') === 1 && ( diff --git a/frontend/providers/dbprovider/src/utils/json2Yaml.ts b/frontend/providers/dbprovider/src/utils/json2Yaml.ts index c32658e29bf..28df56496bf 100644 --- a/frontend/providers/dbprovider/src/utils/json2Yaml.ts +++ b/frontend/providers/dbprovider/src/utils/json2Yaml.ts @@ -111,9 +111,9 @@ export const json2CreateCluster = (data: DBEditType, backupInfo?: BackupItemType spec: { affinity: { nodeLabels: {}, - podAntiAffinity: 'Preferred', + podAntiAffinity: 'Required', tenancy: 'SharedNode', - topologyKeys: [] + topologyKeys: ['kubernetes.io/hostname'] }, clusterDefinitionRef: 'apecloud-mysql', clusterVersionRef: data.dbVersion, @@ -1064,6 +1064,23 @@ export const json2NetworkService = ({ weaviate: '', milvus: '' }; + const labelMap = { + postgresql: { + 'kubeblocks.io/role': 'primary' + }, + mongodb: { + 'kubeblocks.io/role': 'primary' + }, + 'apecloud-mysql': { + 'kubeblocks.io/role': 'leader' + }, + redis: {}, + kafka: {}, + qdrant: {}, + nebula: {}, + weaviate: {}, + milvus: {} + }; const template = { apiVersion: 'v1', @@ -1072,7 +1089,8 @@ export const json2NetworkService = ({ name: `${dbDetail.dbName}-export`, labels: { 'app.kubernetes.io/instance': dbDetail.dbName, - 'apps.kubeblocks.io/component-name': dbDetail.dbType + 'apps.kubeblocks.io/component-name': dbDetail.dbType, + ...labelMap[dbDetail.dbType] }, ownerReferences: [ {